Unique Assembly name every build

会有一股神秘感。 提交于 2019-12-23 02:32:59

问题


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.


回答1:


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: http://phoebix.com/2013/08/08/who-got-the-func-part-3-generating-a-guid-in-msbuild/



来源:https://stackoverflow.com/questions/30089576/unique-assembly-name-every-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!