gre*_*kes 4 asp.net msbuild vs-web-site-project publish-profiles
我正在使用新的 ASP.Net 和 Web 工具 2012.2发布网站配置文件(不是 Web 应用程序)。
我使用在网站根目录中创建文件的工具创建了一个发布配置文件website.publishproj
。
该website.publishproj
文件包含以下内容:
<AssemblyAttributes Include="AssemblyFileVersion">
<Value>$(AssemblyFileVersion)</Value>
</AssemblyAttributes>
<AssemblyAttributes Include="AssemblyVersion">
<Value>$(AssemblyVersion)</Value>
</AssemblyAttributes>
Run Code Online (Sandbox Code Playgroud)
这表明您可以将属性传递给 MSBuild 以设置输出 dll 的版本。
但是,网站的单个输出程序集(编译后合并为单个程序集)始终具有版本号1.0.0.0
.
我试过传入,/p:AssemblyFileVersion=2.1.0.0;AssemblyVersion=2.1.0.0
但这没有效果。
我什至尝试过直接编辑 website.publishproj 文件,但这也没有效果。
有谁知道当您希望将其合并到单个程序集时如何在网站项目上设置输出程序集的版本号?
我已经设法解决了这个问题。我认为这是工具的错误。
如果将OutputPath
属性设置为website.publishproj
文件中的相对路径,则不考虑AssemblyVersion
和AssemblyFileVersion
属性。
这是由于在将网站程序集合并为一个程序集时此版本控制的工作方式。
发生的情况是AssemblyInfo.cs
在部署期间生成一个文件并输入提供的版本号。AssemblyInfo.cs
然后将此文件编译为AssemblyInfo.dll
包含您传入的版本号的文件。
然后aspnet_merge.exe
使用copyattrs
指向AssemblyInfo.dll
它之前生成的参数调用。
如果设置OutputPath
为相对路径,则此copyattrs
参数指向不存在的 dll。这是因为它是从 aspnet_merge.exe 工具所在的路径运行的。因此,返回AssemblyInfo.dll
程序集的相对路径找不到它的真实位置。
OutputPath
不能是相对的。
为了解决这个问题,我将我的设置为:
<PropertyGroup>
<OutputPath>$(MSBuildProjectDirectory)\..\..\TempPackageBuildDir\</OutputPath>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
为什么要费心设置OutputPath
呢?
当您不设置OutputPath
它时,它使用环境变量中的临时目录。就我而言,这会导致构建失败,因为某些文件的文件长度超过了 260 个字符的窗口限制(我有一个非常大的网站)。我完全可以让它构建的唯一方法是将其设置OutputPath
为更浅的路径。