使用 MSBuild 构建 ASP.Net 网站不同于 Visual Studio 构建
Build ASP.Net Website with MSBuild is different from Visual Studio build
我有一个旧的 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\s\XXXX\XXXX.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "debug|any cpu".
Project "C:\TFSAgent\Agent01\_work\s\XXXX\XXXX.sln" (1) is building "C:\TFSAgent\Agent01\_work\s\XXXX\XXXX.metaproj" (2) on node 1 (default targets).
Build:
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\BarcodePrinter.dll" to "..\XXXX\Bin\BarcodePrinter.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\IDAutomation.LinearBarCode.dll" to "..\XXXX\Bin\IDAutomation.LinearBarCode.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\zxing.dll" to "..\XXXX\Bin\zxing.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\BarcodePrinter.pdb" to "..\XXXX\Bin\BarcodePrinter.pdb".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\zxing.pdb" to "..\XXXX\Bin\zxing.pdb".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\zxing.xml" to "..\XXXX\Bin\zxing.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.dll" to "..\XXXX\Bin\System.Net.Http.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.xml" to "..\XXXX\Bin\System.Net.Http.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.Formatting.dll" to "..\XXXX\Bin\System.Net.Http.Formatting.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.Formatting.xml" to "..\XXXX\Bin\System.Net.Http.Formatting.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.WebRequest.dll" to "..\XXXX\Bin\System.Net.Http.WebRequest.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.WebRequest.xml" to "..\XXXX\Bin\System.Net.Http.WebRequest.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Web.Http.dll" to "..\XXXX\Bin\System.Web.Http.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Web.Http.xml" to "..\XXXX\Bin\System.Web.Http.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Web.Http.WebHost.dll" to "..\XXXX\Bin\System.Web.Http.WebHost.dll".
Copying file from "C:\TFSAgent\Agent01\_work\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
我得到了很多我没有得到的 DLL(例如 App_Code.dll
) TFS/MSBuild 构建之后。
我尝试添加/p:DeployOnBuild=true
但没有解决。
那么我如何构建这个项目并准备发布?
这是预期的行为。因为您正在尝试使用 MSBuild 命令来构建网站项目 (metaproj)。然后它创建一个 PrecompiledWeb 文件夹并将代码放在那里。
After creating a publish profile in Visual Studio the following are
created:
1) A publish profile (.pubxml file) under App_Data/PublishProfiles
2) A website.publishproj in the root of the website
The purpose of the website.publishproj is to facilitate command line
publishing. Then you can try to use command like the following:
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 命令和任务,有关详细信息,请查看此问题的答案:
我有一个旧的 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\s\XXXX\XXXX.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "debug|any cpu".
Project "C:\TFSAgent\Agent01\_work\s\XXXX\XXXX.sln" (1) is building "C:\TFSAgent\Agent01\_work\s\XXXX\XXXX.metaproj" (2) on node 1 (default targets).
Build:
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\BarcodePrinter.dll" to "..\XXXX\Bin\BarcodePrinter.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\IDAutomation.LinearBarCode.dll" to "..\XXXX\Bin\IDAutomation.LinearBarCode.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\zxing.dll" to "..\XXXX\Bin\zxing.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\BarcodePrinter.pdb" to "..\XXXX\Bin\BarcodePrinter.pdb".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\zxing.pdb" to "..\XXXX\Bin\zxing.pdb".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\zxing.xml" to "..\XXXX\Bin\zxing.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.dll" to "..\XXXX\Bin\System.Net.Http.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.xml" to "..\XXXX\Bin\System.Net.Http.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.Formatting.dll" to "..\XXXX\Bin\System.Net.Http.Formatting.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.Formatting.xml" to "..\XXXX\Bin\System.Net.Http.Formatting.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.WebRequest.dll" to "..\XXXX\Bin\System.Net.Http.WebRequest.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Net.Http.WebRequest.xml" to "..\XXXX\Bin\System.Net.Http.WebRequest.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Web.Http.dll" to "..\XXXX\Bin\System.Web.Http.dll".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Web.Http.xml" to "..\XXXX\Bin\System.Web.Http.xml".
Copying file from "C:\TFSAgent\Agent01\_work\s\XXXX\bin\System.Web.Http.WebHost.dll" to "..\XXXX\Bin\System.Web.Http.WebHost.dll".
Copying file from "C:\TFSAgent\Agent01\_work\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
我得到了很多我没有得到的 DLL(例如 App_Code.dll
) TFS/MSBuild 构建之后。
我尝试添加/p:DeployOnBuild=true
但没有解决。
那么我如何构建这个项目并准备发布?
这是预期的行为。因为您正在尝试使用 MSBuild 命令来构建网站项目 (metaproj)。然后它创建一个 PrecompiledWeb 文件夹并将代码放在那里。
After creating a publish profile in Visual Studio the following are created:
1) A publish profile (.pubxml file) under App_Data/PublishProfiles
2) A website.publishproj in the root of the website
The purpose of the website.publishproj is to facilitate command line publishing. Then you can try to use command like the following:
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 命令和任务,有关详细信息,请查看此问题的答案: