【问题标题】:Build ASP.Net Website with MSBuild is different from Visual Studio build使用 MSBuild 构建 ASP.Net 网站与 Visual Studio 构建不同
【发布时间】:2020-03-09 09:35:51
【问题描述】:

我有一个旧的 ASP.Net 网站解决方案,看起来像:

当我在 Visual Studio 中构建解决方案时,我得到以下输出:

------ Build started: Project: C:\...\XXXX\, Configuration: Debug Any CPU ------

Validating Web Site
Building directory '/XXXX/App_Code/'.
Building directory '/XXXX/App_WebReference/'.
Building directory '/XXXX/js/'.
Building directory '/XXXX/msg/'.
Building directory '/XXXX/z_admin/'.
Building directory '/XXXX/z_emulationDialogs/'.
Building directory '/XXXX/'.

但是当我使用 TFS(MSBuild 任务)构建它或使用解决方案运行 msbuild.exe 时,我得到了另一个输出:

Project "C:\TFSAgent\Agent01\_work\1\s\XXXX\XXXX.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "debug|any cpu".
Project "C:\TFSAgent\Agent01\_work\1\s\XXXX\XXXX.sln" (1) is building "C:\TFSAgent\Agent01\_work\1\s\XXXX\XXXX.metaproj" (2) on node 1 (default targets).

Build:

  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\BarcodePrinter.dll" to "..\XXXX\\Bin\BarcodePrinter.dll".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\IDAutomation.LinearBarCode.dll" to "..\XXXX\\Bin\IDAutomation.LinearBarCode.dll".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\zxing.dll" to "..\XXXX\\Bin\zxing.dll".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\BarcodePrinter.pdb" to "..\XXXX\\Bin\BarcodePrinter.pdb".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\zxing.pdb" to "..\XXXX\\Bin\zxing.pdb".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\zxing.xml" to "..\XXXX\\Bin\zxing.xml".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Net.Http.dll" to "..\XXXX\\Bin\System.Net.Http.dll".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Net.Http.xml" to "..\XXXX\\Bin\System.Net.Http.xml".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Net.Http.Formatting.dll" to "..\XXXX\\Bin\System.Net.Http.Formatting.dll".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Net.Http.Formatting.xml" to "..\XXXX\\Bin\System.Net.Http.Formatting.xml".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Net.Http.WebRequest.dll" to "..\XXXX\\Bin\System.Net.Http.WebRequest.dll".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Net.Http.WebRequest.xml" to "..\XXXX\\Bin\System.Net.Http.WebRequest.xml".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Web.Http.dll" to "..\XXXX\\Bin\System.Web.Http.dll".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Web.Http.xml" to "..\XXXX\\Bin\System.Web.Http.xml".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Web.Http.WebHost.dll" to "..\XXXX\\Bin\System.Web.Http.WebHost.dll".
  Copying file from "C:\TFSAgent\Agent01\_work\1\s\XXXX\bin\System.Web.Http.WebHost.xml" to "..\XXXX\\Bin\System.Web.Http.WebHost.xml".
  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe -v /XXXX -p ..\XXXX\ -u -f -d PrecompiledWeb\XXXX\

在此构建后我没有得到所有 DLL 的问题,如果我在 VS 中创建 publish,我得到了很多在 TFS/MSBuild 构建后我没有得到的 DLL(例如 App_Code.dll)。

我尝试添加/p:DeployOnBuild=true,但没有解决。

那么我该如何构建这个项目并准备发布呢?

【问题讨论】:

  • 您在本地使用的是哪个版本的 Visual Studio?您在 TFS 上有哪个 MSBuild 版本?
  • 我在这两个版本中都尝试过使用 Visual Studio 2017(项目最初是 2012 年,但我在 VS 2017 中进行了测试,构建输出与 2012 年相同)
  • 我再次检查,突然我看到构建生成的PreCompiledWeb 文件夹,所有的DLL都存在那里。我之前没注意!所以我想我应该从那里拿文件:)

标签: c# asp.net tfs msbuild


【解决方案1】:

这是预期的行为。因为您正在尝试使用 MSBuild 命令来构建网站项目 (metaproj)。然后它创建一个 PrecompiledWeb 文件夹并将代码放在那里。

在 Visual Studio 中创建发布配置文件后,以下是 创建:

1) App_Data/PublishProfiles 下的发布配置文件(.pubxml 文件)

2) 网站根目录中的 website.publishproj

website.publishproj 的目的是方便命令行 出版。然后你可以尝试使用如下命令:

C:\Program Files (x86)\Microsoft Visual Studio 14.0>msbuild "C:\Users\UserName\Documents\Visual Studio2015\WebSites\WebSite1\website.publishproj" /p:deployOnBuild=true /p:publishProfile=WebsiteTestDemo /p:VisualStudioVersion=14.0

请使用website.publishproj 代替MSBuild 命令和任务,有关更多详细信息,请查看此问题的答案:Publish Artifacts for website goes to PrecompiledWeb

【讨论】:

  • 谢谢@Patrick!我可以只从compiledWeb 文件夹中获取文件而不是创建.pubxml 文件吗?
  • @ShaykiAbramczyk 是的,理论上。您可以这样做,因为生成的 dll 仅用于发布。而.pubxml 文件: 1.包含发布配置设置并由发布过程使用。 2.可以修改自定义构建和发布过程。但是,这确实不是常见的情况。对于那种旧的 ASP.Net 网站解决方案,我们通常直接使用 vs build 任务。建议你在你身边仔细检查和测试。
  • VS build task 会给我其他结果而不是 msbuild task?
  • 有差不多的。 stackoverflow.com/questions/39667822/… 但是,在您的情况下,即使您通过 Visual Studio 和 MSBuild 命令行在本地构建,您也会得到不同的结果。这是由于 ASP.Net 网站解决方案。与任务本身无关。
  • 谢谢!我创建了pubxml 文件,效果很好。
猜你喜欢
  • 2017-12-05
  • 1970-01-01
  • 2023-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多