24119

Unique Assembly name every build

Question:

I’m trying to change the Assembly name of my dll during build. I’ve created another exe that changes the assembly name in the csproj file, which I execute during pre-build. But it seems like my changes to the csproj file only take effect after the build has finished, which is of course not what I want.

The assembly name has to be unique every time it gets built, so I create it by appending a GUID.

var xmlDoc = XDocument.Load(projectFile); XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003"; string newAssemblyName = originalAssemblyName + "_" + Guid.NewGuid().ToString("N"); xmlDoc.Element(ns + "Project").Element(ns + "PropertyGroup").Element(ns + "AssemblyName").Value = newAssemblyName; xmlDoc.Save(projectFile);

I was wondering if there is maybe a way to ‘force’ reload the csproj during pre-build or if there is another way I could get a unique assembly name everytime I build my solution.

Answer1:

I had some success doing this inside the csproj file in VS2013:

<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> [...] <PropertyGroup> <MyNewGuid>$([System.Guid]::NewGuid())</MyNewGuid> </PropertyGroup> [...] <AssemblyName>$(MyNewGuid)</AssemblyName>

At least, every time I do a Rebuild it appears to generate an assembly with a different GUID for a name.

If you are using an especially old version of msbuild, you might want to look here for an alternative way to create GUIDs: <a href="http://phoebix.com/2013/08/08/who-got-the-func-part-3-generating-a-guid-in-msbuild/" rel="nofollow">http://phoebix.com/2013/08/08/who-got-the-func-part-3-generating-a-guid-in-msbuild/</a>

Recommend

  • Get user email using facebook toolkit
  • XNode.DeepEquals unexpectedly returns false
  • Unable to format Xml for Excel
  • Containable to do show deeper data or join table
  • XElement default namespace on attributes provides unexpected behaviour
  • how to RSSFeeds from Multiple Websites
  • How to swap two XML elements in linq to xml
  • Could not find or load assembly \"tmpAssembly,
  • XML delete node according to timestamp C#
  • XslTransform with xml-stylesheet
  • How to read key/value in xml file
  • Is there a greater chance to collide when comparing GUIDs based on a hash vs \"Guid.NewGuid()?
  • Append the commit message automatically to the file being committed in Git
  • Append Textarea result from another class
  • Cannot page through all results using nextPageToken on YouTube search API v3
  • how to set to NULL all the filestream varbinary(max) fields?
  • What's the syntax to inherit documentation from another indexer?
  • encoding issues with content in response from HttpWebRequest
  • CERN ROOT exporting data to plain text
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • Loading .coffee files via a view in Rails
  • Create DicomImage from scratch using Dcmtk
  • Jetty 9 HashLoginService
  • How to create a file in java without a extension
  • Cancel a live stream “fast motion” catch-up in Flash
  • Spring Data JPA custom method causing PropertyReferenceException
  • Splitting given String into two variables - php
  • What is Eclipse's Declaration View used for?
  • Counter field in MS Access, how to generate?
  • Possible to stop flickering java tooltip in heavyweight mode?
  • sending/ receiving email in Java
  • How to set my toolbar fixed while scrolling android
  • AT Commands to Send SMS not working in Windows 8.1
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • using HTMLImports.whenReady not working in chrome
  • Authorize attributes not working in MVC 4
  • apache spark aggregate function using min value
  • EntityFramework adding new object to nested object collection
  • Sorting a 2D array using the second column C++
  • How to load view controller without button in storyboard?