1

I have a multiproject solution written c#. I created a sharedassemblyinfo.cs file to share version number, etc...across the different projects in my solution. I need to build this project as a nuget package. In my nuspec file there's placeholders like $version$ that pull the assembly version from the assemblyinfo.cs file. Since I am using instead a sharedassemblyinfo.cs file to hold the assembly version is there a way I can modify my nuspec file to pull the version from sharedassemblyinfo.cs instead of assemblyinfo.cs?

  • Did you try to share existing assemblyinfo.cs (as a link) not create a new? If you use command line you can immediatly define version that ovveride version in .nuspec, [see](https://learn.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference#pack) – George Alexandria Jun 20 '17 at 21:36
  • I create a sharedassemblyinfo.cs at the solution level and each project adds a reference to this as a link. Then each project also has it's own assemblyinfo.cs file for project specific things like guid, description, etc... The sharedassemblyinfo has the assembly version shared across all projects. I'm not familiar with the commandline or what you referenced me to. I just add a nuspec file and build my project using msbuild to create the package. It's throwing an error on assembly version because it's looking in assemblyinfo and not sharedassemblyinfo – Nighttrain5150 Jun 21 '17 at 00:48
  • Not, AFAIK, this is designed by nuget to use AssemblyVersionAttribute attribute in the assemblyinfo.cs when the token $version$ is used. If you want to change it to use sharedassemblyinfo.cs, you have to edit the nuget source code to load that file, digging into NuGet source code, I've found that it's not as straight forward as one might think. – Leo Liu Jun 21 '17 at 10:47
  • Besides, if you replace the $version$ token with a value, then that value will take precendence and will be used in the package file name. You can also set the version on the command line, which takes precedence over all of the above. – Leo Liu Jun 21 '17 at 10:50
  • That's a bummer. I guess I'll just have to manually set the version number in the nuspec file. Was just curious if I could somehow automate this to use the sharedassemblyinfo.cs file and pull the version number from there. Not a big deal it's just another manual step i'll have to remember to do when I want to push a new build. I'll have to update my version number in sharedassemblyinfo.cs and then also update the version in the nuspec file. – Nighttrain5150 Jun 21 '17 at 14:17

1 Answers1

0

is there a way I can modify my nuspec file to pull the version from sharedassemblyinfo.cs instead of assemblyinfo.cs?

Not, AFAIK, this is designed by nuget to use AssemblyVersionAttribute attribute in the assemblyinfo.cs when the token $version$ is used. If you want to change it to use sharedassemblyinfo.cs, you have to edit the nuget source code to load sharedassemblyinfo.cs file, After digging into NuGet source code, I've found that it's not as straight forward as one might think. But you can discuss this question on the GitHub.

Besides, you can manually change the version number in the nuspec file. if you replace the $version$ token with a value, then that value will take precendence and will be used in the package file name. You can also set the version on the command line, which takes precedence over all of the above.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135