简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM