我正在嘗試使用MSBuild根據分支名稱自動更新包版本。這適用於項目本身,但引用的項目(使用相同的MSBuild目標)使用默認版本 - 這意味着我的目標沒有運行。例如,假設我有以下項目:
- ConsoleApp1
- ProjectReference:ClassLibrary1的
- ClassLibrary1的
建設上空時,我得到以下nuspec/nugets :
- ConsoleApp1
version 0.0.2-beta00001
dependency id="ClassLibrary1" version="1.0.0"
- ClassLibrary
version 0.0.2-beta00001
注意,正在通過拉PackageVersion
是爲ProjectReference
默認,而項目本身與發現包建設版。
我試過改變GetTargetPathDependsOn
以及BeforeTargets="GetTargetPath;GetProjectsReferencingProjectJson"
(在Nuget Pack MSBuild中打開後),但它們似乎沒有效果。
<PropertyGroup>
<BuildDependsOn>
OverridePackageVersion;
$(BuildDependsOn);
</BuildDependsOn>
<GetTargetPathDependsOn>
OverridePackageVersion;
$(GetTargetPathDependsOn);
</GetTargetPathDependsOn>
</PropertyGroup>
<Target Name="OverridePackageVersion"
BeforeTargets="GetTargetPath;GetProjectsReferencingProjectJson"
DependsOnTargets="GetDefaultVersion">
<CreateProperty
Value=""
Condition="'$(AutoPackagePreName)'=='$(ReleaseBranchName)'">
<Output TaskParameter="Value" PropertyName="AutoPackagePreName" />
</CreateProperty>
<CreateProperty
Value="$([System.String]::Format($(AutoPackagePreNumberFormat), $([MSBuild]::Add($(AutoPackagePreNumber), 0))))">
<Output TaskParameter="Value" PropertyName="AutoPackagePreNumber" />
</CreateProperty>
<!-- Final Override -->
<CreateProperty
Value="$(AutoPackageVersion)"
Condition="'$(AutoPackagePreName)'==''">
<Output TaskParameter="Value" PropertyName="PackageVersion" />
</CreateProperty>
<CreateProperty
Value="$(AutoPackageVersion)-$(AutoPackagePreName)$(AutoPackagePreNumber)"
Condition="'$(AutoPackagePreName)'!=''">
<Output TaskParameter="Value" PropertyName="PackageVersion" />
</CreateProperty>
<CreateProperty
Value="$(PackageVersion)"
Condition="'$(UpdateVersion)'=='true'">
<Output TaskParameter="Value" PropertyName="Version" />
</CreateProperty>
<Message Importance="High" Text="Selected package version $(PackageVersion)." />
</Target>
這是否可能,或者我將不得不在我的CI中使用Powershell?