如何在 AppVeyor 和 GitVersion 中将项目引用为具有特定版本的包依赖项?

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

我的 appveyor.yml 中有以下 after_build 定义:

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

现在,我有那两个 .proj-文件,其中包含相应的 .nuspec-文件:

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

最后,我对 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打包成功:

Attempting to build package from 'Caliburn.Micro.Contrib.Controller.csproj'.
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild.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'.

extras_project_file 失败:

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.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.

我什至不确定这个功能(<dependencies> 中的令牌替换)是否真的可用。

如果不是,我还能如何将两个 .csproj 文件打包成两个单独的 .nupkg 文件,其中一个依赖于另一个具有特定版本(与要构建的包)?

我已经找到了这种情况的方法 - 但它错过了 %AssemblyInformationalVersion% 作为属性被标记到最终 .dll 文件中(所以我需要检查 GitVersionInformation-class为实际值)。

我将 assembly-informational-format: '{LegacySemVerPadded}' 添加到 GitVersion.yml

接下来,我删除了 .nuspec 中的附加 dependencies 元素,因此两者再次匹配 (=reset)。

最后,我调整了我的 after_build:

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