Search code examples
nugetappveyornuget-specgitversion

How can I reference a project as a package dependency with a specific version in AppVeyor and GitVersion?


I have following after_build definitions in my appveyor.yml:

after_build:
- cmd: nuget pack "%project_file%" -properties "Configuration=%configuration%" -version "%GitVersion_NuGetVersion%" -symbols
- cmd: nuget pack "%extras_project_file%" -properties "Configuration=%configuration%" -version "%GitVersion_NuGetVersion%" -symbols

Now, I have those two .proj-files, which contain a corresponding .nuspec-file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <authors>$author$</authors>
  </metadata>
</package>

Finally, I have a little addition for the extras_project_file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <authors>$author$</authors>
    <dependencies>
      <dependency id="***project_name***" version="$version$" />
    </dependencies>
  </metadata>
</package>

Actually, project_name is replaced with a hardcoded value for simplicity reasons - no injection with -properties yet. Secondly, any project related elements, such as description and authors, have been omitted to provide a neutral question, despite being mandatory for the actual packing.

project_file is packed succesfully:

Attempting to build package from 'Caliburn.Micro.Contrib.Controller.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Packing files from 'C:\projects\dotnet-caliburn-micro-contrib-controller\src\Caliburn.Micro.Contrib.Controller\bin\Release'.
Using 'Caliburn.Micro.Contrib.Controller.nuspec' for metadata.
Found packages.config. Using packages listed as dependencies
Successfully created package 'C:\projects\dotnet-caliburn-micro-contrib-controller\Caliburn.Micro.Contrib.Controller.0.1.0-unstable0068.nupkg'.

Whereas extras_project_file fails:

Attempting to build package from 'Caliburn.Micro.Contrib.Controller.Extras.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Packing files from 'C:\projects\dotnet-caliburn-micro-contrib-controller\src\Caliburn.Micro.Contrib.Controller.Extras\bin\Release'.
Using 'Caliburn.Micro.Contrib.Controller.Extras.nuspec' for metadata.
Found packages.config. Using packages listed as dependencies
Versions using SemVer 2.0.0 are not supported: 0.1.0-unstable.68+Branch.develop.Sha.7f85e35f315f7fe3ecd35762b65802e5467a57c2.

I am not even sure that this feature (token replacement in <dependencies>) is actually available.

If not, how else can I package two .csproj-files into two separate .nupkg-files, where one has a dependency on the other one with a specific version (same version as the package to build)?


Solution

  • I have found a way for this scenario - but it misses %AssemblyInformationalVersion% being stamped into the final .dll-file as an attribute (so I'll need to inspect the GitVersionInformation-class for the actual value).

    I added assembly-informational-format: '{LegacySemVerPadded}' to GitVersion.yml.

    Next, I removed the additional dependencies-element in .nuspec, so both match again (=reset).

    Finally, I adapted my after_build:

    after_build:
      cmd: nuget pack "%project_file%" -properties "Configuration=%configuration%" -symbols 
      cmd: nuget pack "%extras_project_file%" -properties "Configuration=%configuration%" -IncludeReferencedProjects -symbols