我正在尝试通过Visual Studio的构建过程来创建/推送nuget包,如here所述。
建立包装很简单:
<Exec WorkingDirectory="$(ProjectDir)" Command="$(NuGetApp) pack $(ProjectFile) -OutputDirectory $(Deploy) -Verbose -Prop Configuration=Release"/>
我在$(Deploy)文件夹中看到.nupkg文件。
但是为了能够推送它,我需要$(AssemblyVersion)才能在其中使用它:
<Exec Command="$(NuGetApp) push $(ProjectName)$(AssemblyVersion) -s $(NugetServer) $(NugetKey)" />
我尝试使用XMLRead来获取值,但是NugetSpecFile中的值为“$ version $”,而不是AssemblyInfo.cs的版本。
<XmlRead XPath="/package/metadata/version" XmlFileName="$(NuSpecFile)">
<Output TaskParameter="Value" PropertyName="AssemblyVersion" />
</XmlRead>
如何访问版本,以便可以在“nuget push”中使用它?
最佳答案
我会做的:
<PropertyGroup>
<MyAssemblies>somedll\the.dll</MyAssemblies>
</PropertyGroup>
<Target Name="RetrieveIdentities">
<GetAssemblyIdentity
AssemblyFiles="$(MyAssemblies)">
<Output
TaskParameter="Assemblies"
ItemName="MyAssemblyIdentities"/>
</GetAssemblyIdentity>
<Message Text="Files: %(MyAssemblyIdentities.Version)"/>
</Target>
从此处更改:
MSBuild Task to read version of dll
关于msbuild - 从MSBuild中的AssemblyInfo访问版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10709677/