Alex Rivera | Logout

How to get version number in post-build event

Asked 2011-09-20T14:14:32.563
15

I want to use post-build event to automatically create a nuget package and then copy it to a shared folder on our network, something like this (the version number 1.0.0.0. is specified inside the MyLib.nuspec file):

nuget.exe pack "$(SolutionDir)MyLib.nuspec"
xcopy /Y "$(TargetDir)MyLib.1.0.0.0.nupkg" \\folder\subfolder\NuGetPackages

This works, but now I would like to update this script, so that it would include the assembly version also, but I cannot get assembly version inside the post-build event. I would need something like this:

nuget.exe pack -Version $(AssemblyVersion) "$(SolutionDir)MyLib.nuspec"
xcopy /Y "$(TargetDir)MyLib." + $(AssemblyVersion) + ".nupkg" \\folder\subfolder\NuGetPackages

But the $(AssemblyVersion) variable does not exists... Any ideas?

Edit
Report

1 Answer

5

Try this:

Edit your .csproj file and add this block:

<Target Name="AfterBuild">
    <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
        <Output TaskParameter="Assemblies" ItemName="CurrentAssembly" />
    </GetAssemblyIdentity>
    <Exec Command="xcopy /Y $(TargetDir)MyLib.%(CurrentAssembly.Version).nupkg \\folder\subfolder\NuGetPackages"></Exec>
</Target>
answered 2011-10-24T16:42:36.230

Your Answer