问题
I am trying to create/push nuget package through visual studio build process as explained here.
Building package is easy:
<Exec WorkingDirectory="$(ProjectDir)" Command="$(NuGetApp) pack $(ProjectFile) -OutputDirectory $(Deploy) -Verbose -Prop Configuration=Release"/>
I see .nupkg file in $(Deploy) folder.
But to be able to push it, I need $(AssemblyVersion) to use it in :
<Exec Command="$(NuGetApp) push $(ProjectName)$(AssemblyVersion) -s $(NugetServer) $(NugetKey)" />
I tried XMLRead to fetch the value, but value in NugetSpecFile is "$version$" instead of version from AssemblyInfo.cs.
<XmlRead XPath="/package/metadata/version" XmlFileName="$(NuSpecFile)">
<Output TaskParameter="Value" PropertyName="AssemblyVersion" />
</XmlRead>
How do I access version so I could use it in "nuget push"?
回答1:
This i'll do it:
<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>
Altered from here: MSBuild Task to read version of dll
来源:https://stackoverflow.com/questions/10709677/access-version-from-assemblyinfo-in-msbuild