0

I have a winforms app, which is deployed via click-once publishing. Assuming my tests are correct, the only way to have this same app installed more than once in the same machine, is the each publish be made for a different Assembly Name.

My problem is that I am running the msbuild via jenkins, and, to accomplish the above, I would add /p:AssemblyName={whatever}, which will rename all assemblies generated by the build to this same {whatever} value. If the output of my build is 1 exe and 5 dlls, all 6 files will be named {whatever}.

Which in turn raises CS1704: An assembly with the same simple name {whatever} has already been imported.

Is the only way out of this to perform all csc.exe calls that msbuild generates, myself, and see if I can set different assembly names per project ?

Or are there other ways to solve this ?

Veverke
  • 9,208
  • 4
  • 51
  • 95

1 Answers1

1

The problem here is that every property passed to MSBuild as a command line argument is considered a global property and will override the property on all projects built in that invocation. The solution is to introduce an intermediate property that only the "main" project consumes.

Edit the app's csproj file to include this (in the place where AssemblyName is already defined - assuming here that WindowsFormsApp1 is the name of the application):

<AssemblyName>WindowsFormsApp1</AssemblyName>
<AssemblyName Condition="'$(OverrideAssemblyName)' != ''">$(OverrideAssemblyName)</AssemblyName>

you can then use the msbuild commands using /p:OverrideAssemblyName=AnotherName without creating conflicting assembly names on referenced libraries. The property is still defined globally, but only one project consumes it.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • Hey Martin, thanks for helping. I **included** the 2nd line, below the 1st, as instructed. Was I supposed to replace the original AssemblyName line ? – Veverke May 24 '17 at 09:13
  • No, you can leave that as it is. The idea is to overwrite the original name when `/p:OverrideAssemblyName=AnotherName` is passed – Martin Ullrich May 24 '17 at 09:14
  • omg sry i made an error in the condition. i renamed the property after writing and forgot to do it in both places.. updated post – Martin Ullrich May 24 '17 at 09:15
  • It now makes sense, indeed :-) Seems to be working, I have one error left in the jenkins job, will sort it out and will come back to reward your help, thanks a lot ! – Veverke May 24 '17 at 09:16