【问题标题】:How do you set AssemblyVersion when using Publish Profiles (.pubxml) from a Web Site Project?使用网站项目中的发布配置文件 (.pubxml) 时如何设置 AssemblyVersion?
【发布时间】:2013-02-28 22:38:00
【问题描述】:

我正在为网站(不是网络应用程序)使用新的 ASP.Net 和 Web 工具 2012.2 发布配置文件

我使用在网站根目录中创建文件website.publishproj 的工具创建了一个发布配置文件

website.publishproj 文件包含以下内容:

<AssemblyAttributes Include="AssemblyFileVersion">
    <Value>$(AssemblyFileVersion)</Value>
</AssemblyAttributes>
<AssemblyAttributes Include="AssemblyVersion">
    <Value>$(AssemblyVersion)</Value>
</AssemblyAttributes>

这建议您可以将属性传递给 MSBuild 以设置输出 dll 的版本。

但是,网站的单个输出程序集(它被编译然后合并为单个程序集)始终具有版本号 1.0.0.0

我试过传入/p:AssemblyFileVersion=2.1.0.0;AssemblyVersion=2.1.0.0,但这没有效果。

我什至尝试过直接编辑 website.publishproj 文件,但这也没有效果。

当您希望将输出程序集合并到单个程序集时,有谁知道如何在网站站点项目上设置输出程序集的版本号?

【问题讨论】:

    标签: asp.net msbuild web-site-project publish-profiles


    【解决方案1】:

    我已经设法解决了这个问题。我认为这是工具的错误。

    如果您将OutputPath 属性设置为website.publishproj 文件中的相对路径,则AssemblyVersionAssemblyFileVersion 属性将不受尊重。

    这是由于在将网站程序集合并为一个程序集时此版本控制的工作方式。

    在部署期间会生成一个AssemblyInfo.cs 文件并输入提供的版本号。然后这个AssemblyInfo.cs 文件被编译成一个AssemblyInfo.dll 包含你传入的版本号。

    然后调用aspnet_merge.exe 并使用指向它之前生成的AssemblyInfo.dllcopyattrs 参数。

    如果您将OutputPath 设置为相对路径,则此copyattrs 参数指向一个不存在的dll。这是因为它是从 aspnet_merge.exe 工具所在的路径运行的。因此返回AssemblyInfo.dll 程序集的相对路径找不到它的真实位置。

    OutputPath 不能是相对的。

    为了解决这个问题,我将我的设置为:

    <PropertyGroup>
        <OutputPath>$(MSBuildProjectDirectory)\..\..\TempPackageBuildDir\</OutputPath>
    </PropertyGroup>
    

    为什么还要设置OutputPath

    当您不设置OutputPath 时,它会使用环境变量中的临时目录。就我而言,这会导致构建失败,因为某些文件的文件长度超过了 260 个字符的窗口限制(我有一个非常大的网站)。我完全可以构建它的唯一方法是将OutputPath 设置为更浅的路径。

    【讨论】:

    • 我能够直接在&lt;AssemblyFileVersion&gt;&lt;AssemblyVersion&gt; 元素中的website.publishproj 文件中编辑之前的&lt;PropertyGroup&gt; 元素块中的版本。也许这是在提出并回答了这个问题之后的新功能。或者修复了一个错误。无论哪种方式。希望这对其他人有帮助。
    【解决方案2】:

    我遇到了类似的问题,但原因不同。

    我的项目的MSBuild Options &gt; Output folder 路径设置为与我的Publish &gt; Connection &gt; Target location 路径不同的路径,因此它没有从AssemblyInfo.dll 继承版本信息

    希望这对其他人有帮助。

    【讨论】:

      【解决方案3】:

      对我来说,解决方案是将属性添加到我的 .pubxml 文件中。

      <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
          <AssemblyVersion>2.3.0.0</AssemblyVersion>
          <AssemblyFileVersion>2.3.0.0</AssemblyFileVersion>
          ... rest of properties ...
        </PropertyGroup>
      </Project>
      

      【讨论】:

        猜你喜欢
        • 2017-08-30
        • 1970-01-01
        • 2020-10-28
        • 2013-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多