1
votes

I am developing a ClickOnce-deployed application and would like to split my releases into multiple builds (a "stable" release and a "test" release). I know that to keep my test and stable releases separate, I need to set the "AssemblyName" property to be different. Here is what my call to MSBuild looks like in my NAnt script:

<msbuild project="../MyProject/MyProject/MyProject.csproj" target="publish">
  <property name="Configuration" value="Release"/>
  <property name="ApplicationVersion" value="${buildnumber.version}"/>
  <property name="ProductName" value="My Project (Test)"/>
  <property name="AssemblyName" value="MyProjectTest"/>
  <property name="InstallUrl" value="http://www.mycompany.com/software/MyProjectTest/"/>
</msbuild>

However, one of the references of my project is a library which I also wrote myself. The reference is therefore to the .csproj file of the library instead of a DLL. The above MSBuild call seems to force the AssemblyName recursively down, setting the AssemblyName of my library project to also be "MyProjectTest", when I would like it to just be called "MyLibrary".

Here's a snippet from MyProject.csproj (ie. MyProject's MSBuild script), showing the reference to the library:

<ItemGroup>
  <ProjectReference Include="..\..\MyLibrary\MyLibrary\MyLibrary.csproj">
    <Project>{A011B373-74D3-45EF-92E2-F342C572402A}</Project>
    <Name>MyLibrary</Name>
    <Private>True</Private>
  </ProjectReference>
</ItemGroup>

I have a few workarounds which might work, like building the library separately and then setting the reference to point to the compiled DLL instead of the .csproj file, or manually copying-and-pasting the properly-compiled version of the library over from the stable release's folder, but what I would really like is for NAnt to work properly.

So, I suppose my question is this: Is there a way to force the AssemblyName of just one project using NAnt's msbuild task?

Edit: Another little note: Another fellow a few years ago had this same issue but never got a satisfactory solution. You can read the question (and relevant comment) here: Change AssemblyName of a csproject via msbuild

1
There an answer here that looks promising. It means changing your csproj file, but it looks acceptable.James Thorpe
I am not opposed to changing the csproj file at all! This is exactly what I need. Thanks! If you write this as an answer, I'll accept it.Eric Dand
I'd rather just see this question closed as a duplicate of the other (and have voted as such!) - it's close enough that the solution there fits as it's msbuild specific rather than nant. Good to leave this question here as a signpost to the other though.James Thorpe

1 Answers

1
votes

When I need to adjust similar things, I generally use xmlpoke or loadfile/echo to rewrite web.config or assemblyinfo.cs then run the msbuild task merely specifying the solution name. You could also use #if MYTHING to conditionally define the AssemblyName inside assemblyinfo.cs then conditionally pass <arg value='/p:DefineConstants=MYTHING' /> as part of the msbuild task.