.net 构建后的 MsBuild 复制文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12384628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:36:37  来源:igfitidea点击:

MsBuild copy file after build

.netvisual-studio-2010buildmsbuildcsproj

提问by KlimczakM

I want to copy an xml file from the main directory to bin\Debugafter building the project, but my solution doesn't work. I edited .csprojfile and added:

我想bin\Debug在构建项目后从主目录复制一个xml文件,但我的解决方案不起作用。我编辑了.csproj文件并添加了:

<Target Name="AfterBuild">
     <Copy SourceFiles="Controllers.xml" DestinationFolder="\bin\Debug" ContinueOnError="true" />
</Target>

What am I doing wrong? The build is successful.

我究竟做错了什么?构建成功。

回答by Christian.K

Your destination folder is (most likely) wrong. If you specify it with a leading backslash, it is actually just a shortform for <current-drive-letter>\bin\Debug(making it effectively an absolute path, like C:\bin\Debug).

您的目标文件夹(很可能)是错误的。如果您使用前导反斜杠指定它,它实际上只是 for <current-drive-letter>\bin\Debug(使其有效地成为绝对路径,例如C:\bin\Debug)的缩写。

Either use bin\Debug, or better yet use the OutputPathvariable, which is set to either bin\Debugor bin\Releasedepending on your build configuration.

要么使用bin\Debug,要么更好地使用OutputPath变量,该变量设置为bin\Debugbin\Release取决于您的构建配置。

Example:

例子:

<Target Name="AfterBuild">
     <Copy SourceFiles="Controllers.xml" DestinationFolder="$(OutputPath)" ContinueOnError="true" />
</Target>

回答by James Woolfenden

Is the xml file in your project? Then one of its properties is CopyToOutputDirectory. Set it to CopyAlways and when the project builds the file will be copied out to bin\debug.

你的项目中有xml文件吗?那么它的属性之一是 CopyToOutputDirectory。将其设置为 CopyAlways,当项目构建时,文件将被复制到 bin\debug。

回答by Filip De Vos

You have to specify the full path. I suspect the MsBuild copy task is running from the "Default path" of Visual Studio, and the file can not be found. Also, you most likely want the file to end up in the build target directory.

您必须指定完整路径。我怀疑 MsBuild 复制任务正在从 Visual Studio 的“默认路径”运行,并且找不到该文件。此外,您很可能希望文件最终位于构建目标目录中。

<Target Name="AfterBuild">
    <Copy SourceFiles="$(ProjectDir)Controllers.xml" DestinationFolder="$(TargetDir)" ContinueOnError="true" />
</Target>