Access Version from AssemblyInfo in MSBuild

﹥>﹥吖頭↗ 提交于 2019-11-27 23:50:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!