How to use dotnet package with AppVeyor?

I am automating my .NET Standard projects (new csproj format VS 2017) to generate nuget packages after build.

The point is, I want all projects in the solution to match the version of my AppVeyor assembly, not the version set in the csprojs package properties (which is 1.0.0 by default).

Another thing to consider is that my projects have links between them and must also contain the AppVeyor assembly version.

Is there an easy way to do this? How?

+3


source to share


2 answers


You can pass the version as MSBuild property to dotnet pack

:

dotnet pack MyProject.csproj --configuration Release /p:Version="1.2.3"

      

(this works for dotnet build

)

Here's an example in the FakeItEasy build script .



Use an environment variable to get the build number of the AppVeyor APPVEYOR_BUILD_VERSION

.

Another thing to consider is that my projects have links between them and must also contain the AppVeyor assembly version.

This shouldn't be a problem, because you won't specify the version on the element <ProjectReference>

.

+3


source


UPDATE: .NET Core .csproj patch files and automatic nuget packaging for .NET Core projects are working now.


There are several options:

Make a manual fix to the .NET Standard file .csproj

using PowerShell. In this example we are updating the version, but you can update other settings as well.

$xmlPath = "$env:appveyor_build_folder\MyProject\MyProject.csproj"
$xml = [xml](get-content $xmlPath)
$propertyGroup = $xml.Project.PropertyGroup | Where { $_.Version}
$propertyGroup.Version = $env:appveyor_build_version
$xml.Save($xmlPath)
msbuild %appveyor_build_folder%\MyProject\MyProject.csproj /t:pack 

      



or if you want to keep using the .nuspec

file, you can run the command like this:

msbuild %appveyor_build_folder%\MyProject\MyProject.csproj /t:pack /p:Configuration=%CONFIGURATION%;NuspecFile=MyProject\MyProject.nuspec;PackageVersion=%APPVEYOR_BUILD_VERSION%

      

You can of course use dotnet pack

, but we feel that going forward msbuild

will remain the main tool, so we try to use all scenarios using it.

Needless to say, we at AppVeyor have to make this script unnecessary, we track this at https://github.com/appveyor/ci/issues/1404 .

+2


source







All Articles