Getting the post-build version for Nuget

the code:

if $(ConfigurationName) == Release (
    cd $(ProjectDir)
    nuget spec Entities -f
    nuget pack DeusPak.Entities.csproj -Prop Configuration=Release
    nuget push DeusPak.Entities.$(version).nupkg  $(MYGET_API_KEY) -Source     http://www.myget.org/F/lojaali/api/v2/package
)

I just started playing with NuGet and want to know how to include the version number in my NuGet package. I am currently hard-coded it into a post-build event, which is obviously not what I want to keep doing. Can anyone help?

This is my current event after build:

if $(ConfigurationName) == Release (
    cd $(ProjectDir)
    nuget spec Dev-f
    nuget pack Dev.csproj -Prop Configuration=Release
    nuget push Dev.1.0.0.0.nupkg  $(MYGET_API_KEY) -Source     http://www.myget.org/F/api/v2/package
)

Update:

OK, I was able to create a DLL with the correct version number with the version automatically added:

if $(ConfigurationName) == Release (
    cd $(ProjectDir)
    nuget spec Dev -f
    nuget pack Dev.csproj -Prop Configuration=Release
    nuget push Dev.$(version).nupkg  $(MYGET_API_KEY) -Source     http://www.myget.org/F/api/v2/package
)

But this version does not appear on my MyGet package list. How can I show it so that it can be downloaded? Or can this be done only manually by clicking "Add Package"?

+5
source share
3 answers

, , AssemblyVersion AssemblyInfo.cs .

[assembly: AssemblyVersion("1.0.0")]

[assembly: AssemblyVersion("1.0.0.*")]

, AssemblyInformationalVersion AssemblyInfo.cs.

[assembly: AssemblyInformationalVersion("1.0.0")]

, , , Semantic Versioning ( 3 ). , NuGet, nuspec csproj, . FYI, NuGet :

Install-Package NuSpec 

NuGet nuspec (, MyProject.nuspec) MyProject.csproj.

<package>
  <version>$version$</version>
  ...
</package>

MyGet : http://blog.myget.org/post/2012/04/27/NuGet-version-token-explained.aspx

-, nuget, , .

nuget pack MyProject.csproj
+6

, Carlos J López, AfterBuild script NuGet .

"cd $(ProjectDir)" post build, AfterBuild script.

,

    <Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
      <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
          <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
      </GetAssemblyIdentity>
      <Exec Command="$(SolutionDir)\.nuget\nuget pack $(ProjectName).nuspec -Version %(AssemblyVersion.Version)" />
      <Message Text="$(SolutionDir)\.nuget\nuget pack $(ProjectName).nuspec -Version %(AssemblyVersion.Version)" Importance="high" />
    </Target>  
+5

Here's how you can get the $ (version) variable in your post build, which should be as good as post build.

<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
    <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
        <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
    </GetAssemblyIdentity>
    <Exec Command="echo %(AssemblyVersion.Version)" />
    <Message Text="Released %(AssemblyVersion.Version)" Importance="high" />
</Target>

So, you will need to modify your .csproj file, since VS does not provide an interface for it.

+4
source

All Articles