Gianluca Ghettini Gianluca Ghettini - 3 months ago 11
C# Question

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

Tim Tim
Answer

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