SuperJMN
SuperJMN

Reputation: 14002

How to use dotnet pack with AppVeyor?

I'm automating my .NET Standard projects (VS 2017's new csproj format) to generate nuget packages after building.

The thing is that I want all the projects in the solution to follow the version of my AppVeyor build, not the version that is set inside the Package properties of the csprojs (that is defaulted to 1.0.0).

Another thing to take into account is that my projects have references between them and should keep the AppVeyor build version, too.

Is there an easy way to do it? How?

Upvotes: 3

Views: 985

Answers (2)

Ilya Finkelsheyn
Ilya Finkelsheyn

Reputation: 2881

UPDATE: .NET Core .csproj files patching and automatic nuget packaging for .NET Core projects works now.


There are few options:

Do manual patching of .NET Standard .csproj file with PowerShell. In this sample we update version, but you can update other settings too this way.

$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 .nuspec file, you can pack with command like this:

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

Sure you can use dotnet pack but we feel that going forward msbuild will remain main tool, so we try to do all scripting using it.

Needless to say that we in AppVeyor should make this scripting unneeded, we track this in https://github.com/appveyor/ci/issues/1404.

Upvotes: 2

Thomas Levesque
Thomas Levesque

Reputation: 292695

You can pass the version as an MSBuild property to dotnet pack:

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

(this works for dotnet build too)

Here's an example in the FakeItEasy build script.

To get the AppVeyor build number, use the APPVEYOR_BUILD_VERSION environment variable.

Another thing to take into account is that my projects have references between them and should keep the AppVeyor build version, too.

This shouldn't be an issue, because you don't specify a version in the <ProjectReference> element.

Upvotes: 3

Related Questions