Automating creating NuGet package as part of build process

前端 未结 9 1812
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 18:05

I have an automated build process that I\'d like to extend so I can build the libraries I am distributing via NuGet. Currently, running nuget.exe to create the packages is

相关标签:
9条回答
  • 2020-12-22 18:15

    I created a NuGet project type (.nuproj) Visual Studio extension called NuBuild that should do what you want. It allows you to build your NuGet packages from Visual Studio as well as MSBuild. You can install it from the gallery or get the source at github.

    0 讨论(0)
  • 2020-12-22 18:15

    As far as I'm aware, you can't.

    Instead, do it properly and have a proper build environment/process that fires a build script on commit/push to your main repository that does the following:

    • Clone/pull changes.
    • Build solution.
    • Build package(s).
    • Upload package(s) to package server.

    You could run TeamCity, CruiseControl.NET or some other CI server on a VM or on your existing build server.

    0 讨论(0)
  • 2020-12-22 18:18

    A simple suggestion that might work good enough... just put it as Postbuild event into the .csproj file:

      <PropertyGroup>
        <PostBuildEvent>$(SolutionDir)<YourPathToNugetHere>\NuGet.exe pack $(ProjectPath) -OutputDirectory ..\..\$(OutDir) -IncludeReferencedProjects -Symbols -Properties Configuration=$(Configuration)</PostBuildEvent>
      </PropertyGroup>
    

    This will collect your custom .nuspec file (that needs to be named like the .csproj file) and build the .nupkg.

    Thats it.

    You can even do this simply within the Visual Studio Project settings.

    0 讨论(0)
  • 2020-12-22 18:18

    Install the 'NuGet.for.MSBuild' nuget package. No '.nuspec' file is required and the required information will be taken from the AssemblyInfo.cs.

    Set the build to 'Release' mode. Once built the nupkg file will be in the 'bin/Release' folder.

    https://nuget4msbuild.codeplex.com/

    0 讨论(0)
  • 2020-12-22 18:19

    There is the Nuget package CreateNewNuGetPackageFromProjectAfterEachBuild which claims that it can do what you want. There is also a documentation/project site.

    0 讨论(0)
  • 2020-12-22 18:24

    One thing that might work well is to create a custom MSBuild .proj file. You could define a couple targets in the custom script, the first to execute the compile on your solution. A second target to execute following compilation would use the EXEC MSBuild task to invoke the nuget.exe command line utility. Then, you update your batch file-runner to execute the msbuild executable supplying your custom project file as an argument. You might already be using MSBuild in your batch script, which in that case it would simply be a matter of argument swapping. You could include your custom proj file in the solution items of your solution. If you did that you could easily add an external tool reference in Visual Studio to quickly test out your custom script to make sure it was building and producing the package like you hope.

    Sample MSBuild

    You can use this as a starting place:

    <Project DefaultTargets="Compile" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
        <PropertyGroup>
          <SolutionFile></SolutionFile>
          <NugetExecutable>C:\PathToNuget\nuget.exe</NugetExecutable>
          <NuspecFile></NuspecFile>
        </PropertyGroup>
    
        <Target Name = "Compile">
            <MSBuild Projects="$(SolutionFile)" Properties="Configuration=Release" />
        </Target>
    
        <Target Name = "Package">
        <!-- You could use the MSBuild Copy task here to move the compiled code into
               a structure that fits your desired package format -->
          <Exec Command="&quot;$(NugetExecutable)&quot; pack $(NuspecFile)" />
        </Target>
    </Project>
    

    You'd then call this like:

    "C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" Build.proj /p:SolutionFile=PathToSolution\App.sln;NuspecFile=foo.nuspec
    
    0 讨论(0)
提交回复
热议问题