Gianluca Ghettini
Gianluca Ghettini

Reputation: 11628

Setting Nuget package version

I'm using VS2015 and I'm generating a Nuget package out of some C# projects I have.

I'm using this line as my post build step:

nuget.exe pack $(ProjectDir)myproj.csproj -Version 0.1.0 -OutputDirectory $(SolutionDir)

everything's fine but I'd like to pass the version number from an external txt file (something like version.txt). Using the build number as the last version integer would be a plus

Upvotes: 0

Views: 826

Answers (2)

Tim
Tim

Reputation: 2912

You would first need to obtain the version in a separate step (nuget has no concept of loading files for version numbers)

So to get the assemblyinfo of one of your DLLs/exe's you could do something like this:

for /F "tokens=4" %%F in ('filever.exe /B /A /D bin\debug\myproj.dll')    
do (
  set VERSION=%%F
)

You could get the version from a text file similarly by doing the following:

for /f "tokens=1" %%F in (version.txt) do set VERSION=%%F

Upvotes: 1

Newtopian
Newtopian

Reputation: 7712

You could write a MSBuild task that reads the file and then calls the nuget executable with the proper parameters.

Integrating custom MSbuild tasks is easy, just manually edit the csproj file instead of using the property editor from visualStudio. The post build step is actually just a MSBuild task where the editor stuffs the commands you write there.

if you look around a bit you most likely will find tasks already made up to do what (or most of) you want. Quick search turned this up https://msdn.microsoft.com/en-us/library/ms164299.aspx

Upvotes: 1

Related Questions