MSBuild 没有将文件复制到发布文件夹?
Posted
技术标签:
【中文标题】MSBuild 没有将文件复制到发布文件夹?【英文标题】:MSBuild not copying files to the publish folder? 【发布时间】:2022-01-24 06:46:42 【问题描述】:我有一个 .net 框架 MVC 项目,它纯粹是由 Visual Studio 生成的,因为它是示例项目。
当我使用 Visual Studio 2019 发布它时,它运行良好,所有 Web 视图和 dll 都发布到目标文件夹 (bin\app.publish)。
为了在 Jenkins 上测试 CI/CD 管道,我尝试使用 MSBuild 在命令行中按照 Microsoft 的一些示例发布,但它只执行编译并且没有文件发布到目标文件夹。
我的命令和发布配置文件如下所示,谁能告诉我有什么问题?
msbuild jenkins1.csproj /p:DeployOnBuild=true /p:PublishProfile=default
default.pubxml
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DeleteExistingFiles>True</DeleteExistingFiles>
<ExcludeApp_Data>False</ExcludeApp_Data>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\app.publish</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
<SiteUrlToLaunchAfterPublish />
</PropertyGroup>
</Project>
构建输出如下图,我删除了一些重复的行以使其简洁明了。
Microsoft (R) Build Engine version 16.11.1+3e40a09f8 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 23/12/2021 3:20:32 PM.
Project "C:\Users\mduan\source\repos\jenkins2\jenkins1.csproj" on node 1 (Rebuild target(s)).
CoreClean:
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\jenkins1.dll".
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\jenkins1.pdb".
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\csc.exe".
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\csc.exe.config".
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\csc.rsp".
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\csi.exe".
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\csi.exe.config".
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\csi.rsp".
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\Microsoft.Build.Tasks.CodeAnalysis.dll".
Deleting file "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\Microsoft.CodeAnalysis.CSharp.dll".
....................
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the i
nput files.
CoreCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\csc.exe /noconfig /nowarn:17
01,1702 /fullpaths /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:C:\Users\mdu
an\source\repos\jenkins2\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll /reference:C:\Users\mduan\source\repos\jenkins
2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompi
lerPlatform.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\Micr
osoft.CSharp.dll" /reference:C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\n
et40\Microsoft.Web.Infrastructure.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NE
TFramework\v4.7.2\mscorlib.dll" /reference:C:\Users\mduan\source\repos\jenkins2\packages\Newtonsoft.Json.12.0.2\lib\n
et45\Newtonsoft.Json.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4
.7.2\System.ComponentModel.DataAnnotations.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Fra
mework\.NETFramework\v4.7.2\System.Configuration.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microso
ft\Framework\.NETFramework\v4.7.2\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\
Framework\.NETFramework\v4.7.2\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemb
lies\Microsoft\Framework\.NETFramework\v4.7.2\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblie
s\Microsoft\Framework\.NETFramework\v4.7.2\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Micros
oft\Framework\.NETFramework\v4.7.2\System.Drawing.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Micros
oft\Framework\.NETFramework\v4.7.2\System.EnterpriseServices.dll" /reference:"C:\Program Files (x86)\Reference Assemb
lies\Microsoft\Framework\.NETFramework\v4.7.2\System.Net.Http.dll" /reference:"C:\Program Files (x86)\Reference Assem
blies\Microsoft\Framework\.NETFramework\v4.7.2\System.Net.Http.WebRequest.dll" /reference:"C:\Program Files (x86)\Ref
erence Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Web.Abstractions.dll" /reference:"C:\Program Files
(x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Web.ApplicationServices.dll" /reference:"C
:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Web.dll" /reference:"C:\Pr
ogram Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Web.DynamicData.dll" /referenc
e:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Web.Entity.dll" /refer
ence:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\System.Web.Extensions.dll"
/reference:C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helper
s.dll /reference:C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dl
l /reference:C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.W
eb.Optimization.dll /reference:C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\S
ystem.Web.Razor.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\
System.Web.Routing.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.
7.2\System.Web.Services.dll" /reference:C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.AspNet.WebPages.3.2.7
\lib\net45\System.Web.WebPages.Deployment.dll /reference:C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.AspN
et.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll /reference:C:\Users\mduan\source\repos\jenkins2\packages\Microsof
t.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll /reference:"C:\Program Files (x86)\Reference Assembli
es\Microsoft\Framework\.NETFramework\v4.7.2\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\M
icrosoft\Framework\.NETFramework\v4.7.2\System.Xml.Linq.dll" /reference:C:\Users\mduan\source\repos\jenkins2\packages
\WebGrease.1.6.0\lib\WebGrease.dll /debug+ /debug:full /optimize- /out:obj\Debug\jenkins1.dll /subsystemversion:6.00
/target:library /utf8output /langversion:7.3 App_Start\BundleConfig.cs App_Start\FilterConfig.cs App_Start\RouteConfi
g.cs Controllers\HomeController.cs Global.asax.cs Properties\AssemblyInfo.cs "obj\Debug\.NETFramework,Version=v4.7.2.
AssemblyAttributes.cs"
CompilerServer: server - server processed compilation - 2acabf12-862a-4309-a66c-f79b85daae60
_CopyFilesMarkedCopyLocal:
Copying file from "C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Micro
soft.Web.Infrastructure.dll" to "C:\Users\mduan\source\repos\jenkins2\bin\Microsoft.Web.Infrastructure.dll".
Copying file from "C:\Users\mduan\source\repos\jenkins2\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll
" to "C:\Users\mduan\source\repos\jenkins2\bin\Newtonsoft.Json.dll".
Copying file from "C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2
.0.1\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll" to "C:\Users\mduan\source\repos\jenkins2\bin\M
icrosoft.CodeDom.Providers.DotNetCompilerPlatform.dll".
.................................
CopyFilesToOutputDirectory:
Copying file from "C:\Users\mduan\source\repos\jenkins2\obj\Debug\jenkins1.dll" to "C:\Users\mduan\source\repos\jenki
ns2\bin\jenkins1.dll".
jenkins1 -> C:\Users\mduan\source\repos\jenkins2\bin\jenkins1.dll
Copying file from "C:\Users\mduan\source\repos\jenkins2\obj\Debug\jenkins1.pdb" to "C:\Users\mduan\source\repos\jenki
ns2\bin\jenkins1.pdb".
CopyRoslynCompilerFilesToOutputDirectory:
Copying file from "C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2
.0.1\tools\roslynlatest\csi.exe" to "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\csi.exe".
Copying file from "C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2
.0.1\tools\roslynlatest\csc.exe" to "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\csc.exe".
Copying file from "C:\Users\mduan\source\repos\jenkins2\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2
.0.1\tools\roslynlatest\csc.rsp" to "C:\Users\mduan\source\repos\jenkins2\bin\roslyn\csc.rsp".
.................................
Done Building Project "C:\Users\mduan\source\repos\jenkins2\jenkins1.csproj" (Rebuild target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:03.51
【问题讨论】:
【参考方案1】:通过安装NuGet包解决问题:MSBuild.Microsoft.VisualStudio.Web.targets
之前项目文件中的Microsoft.WebApplication.targets
有问题,无法正确发布。
【讨论】:
以上是关于MSBuild 没有将文件复制到发布文件夹?的主要内容,如果未能解决你的问题,请参考以下文章
如何使 MSBuild 自动将所有间接引用复制到输出(bin)文件夹
.Net-Core Proj - MSBuild 无法复制到输出文件夹
Visual Studio/MSBuild 将引用的类库的 app.config 作为 *.dll.config 复制到当前项目的 bin 文件夹