Search code examples
visual-studionuget

Create Nuget package from Visual Studio 2013


I have installed the NuGet.Tools.2013.vsix on my VS2013. And I like to create a Nuget package from Manager Console, but when I try I get a mensagem:

The term 'nuget' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I don't know what I do wrong.

Is possible use the Manager Console to create a package, or I need use other stuff.


Solution

  • Make sure that you have nuget.exe somewhere on %PATH%.

    Note: We use Jenkins and needed EnvInject to get the %PATH% variable available during the build process.

    Edit your .csproj file to include a new macro variable for the assembly version number, see Determine Assembly Version during a Post Build Event?

    <Target Name="PostBuildMacros">
      <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
        <Output TaskParameter="Assemblies" ItemName="Targets" />
      </GetAssemblyIdentity>
      <ItemGroup>
        <VersionNumber Include="@(Targets->'%(Version)')"/>
      </ItemGroup>
    </Target>
    <PropertyGroup>
      <PostBuildEventDependsOn>
        $(PostBuildEventDependsOn);
        PostBuildMacros;
      </PostBuildEventDependsOn>    
      <PostBuildEvent>echo HELLO, THE ASSEMBLY VERSION IS: @(VersionNumber)</PostBuildEvent>
    </PropertyGroup>
    

    Use the following post-build script to deploy new packages whenever the assembly version has changed and a new .nupkg is required;

    IF "$(ConfigurationName)" == "Release" (
      CD /D $(ProjectDir)
      IF EXIST $(TargetName).@(VersionNumber).nupkg EXIT
      nuget pack $(ProjectPath) -Properties Configuration=$(ConfigurationName)
      nuget push $(TargetName).@(VersionNumber).nupkg -s http://mynugetserver
    )