Visual Studio 构建后事件 - 复制到相对目录位置
成功构建后,我希望将输出目录的内容复制到同一“base”文件夹下的不同位置。 此父文件夹是一个相对部分,可能会根据源代码管理设置而有所不同。
我列出了一些可用的宏值...
$(SolutionDir) = D:\GlobalDir\Version\AppName\Solution1\build
$(ProjectDir) = D:\ GlobalDir\Version\AppName\Solution1\Version\ProjectA\
我想将输出目录内容复制到以下文件夹:
D:\GlobalDir\Version\AppName\Solution2\Project\Dependency
需要从上述宏之一获取基本位置“D:\GlobalDir\Version\AppName”。 但是,没有任何宏值仅列出父位置。
如何仅提取构建后复制命令的基本位置?
On a successful build, I wish to copy the contents of the output directory to a different location under the same "base" folder. This parent folder is a relative part and can vary based on Source Control settings.
I have listed a few of the Macro values available to me ...
$(SolutionDir) = D:\GlobalDir\Version\AppName\Solution1\build
$(ProjectDir) = D:\GlobalDir\Version\AppName\Solution1\Version\ProjectA\
I want to copy the Output Dir contents to the following folder :
D:\GlobalDir\Version\AppName\Solution2\Project\Dependency
The base location "D:\GlobalDir\Version\AppName" needs to be fetched from one of the above macros. However, none of the macro values list only the parent location.
How do I extract only the base location for the post build copy command ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
以下是您想要放入项目的构建后事件命令行中的内容:
编辑:或者如果您的目标名称与项目名称不同。
Here is what you want to put in the project's Post-build event command line:
EDIT: Or if your target name is different than the Project Name.
如果 TargetDir 或其他宏都没有指向正确的位置,请使用“..”目录在文件夹层次结构中向后移动。
IE。 使用
$(SolutionDir)\..\..
获取您的基本目录。有关所有宏的列表,请参见此处:
http://msdn.microsoft.com/ en-us/library/c02as0cs.aspx
If none of the TargetDir or other macros point to the right place, use the ".." directory to go backwards up the folder hierarchy.
ie. Use
$(SolutionDir)\..\..
to get your base directory.For list of all macros, see here:
http://msdn.microsoft.com/en-us/library/c02as0cs.aspx
你可以尝试:
You could try:
我认为这是相关的,但是当我直接使用 msbuild 命令行(从批处理文件)构建与从 VS 中构建时遇到了问题。
使用类似以下内容:
(注意:
start XCOPY
而不是XCOPY
用于解决阻止复制的权限问题)宏
$(SolutionDir) 计算结果为
..\
,这导致XCOPY
命令失败。 在 Visual Studio 中构建时它工作得很好。 使用/verbosity:diagnostic
确认以查看评估的输出。使用宏
$(ProjectDir)..\
代替,这相当于相同的事情,工作得很好,并在两个构建场景中保留了完整路径。I think this is related, but I had a problem when building directly using
msbuild
command line (from a batch file) vs building from within VS.Using something like the following:
(note:
start XCOPY
rather thanXCOPY
used to get around a permissions issue which prevented copying)The macro
$(SolutionDir)
evaluated to..\
when executing msbuild from a batchfile, which resulted in theXCOPY
command failing. It otherwise worked fine when built from within Visual Studio. Confirmed using/verbosity:diagnostic
to see the evaluated output.Using the macro
$(ProjectDir)..\
instead, which amounts to the same thing, worked fine and retained the full path in both build scenarios.直接使用msbuild是不是没有意义? 如果您在每次构建时都执行此操作,那么您可以在最后添加一个 msbuild 任务吗? 如果您只是想看看是否找不到 Visual Studio IDE 上未显示的另一个宏值,您可以打开 msbuild 选项进行诊断,这将显示您可以使用的所有变量,如下所示以及它们的当前值。
要在 Visual Studio 中打开此功能,请转到“工具/选项”,然后向下滚动树视图到名为“项目和解决方案”的部分,展开该部分并单击“构建和运行”,右侧是一个下拉列表,用于指定构建输出详细程度,将其设置为诊断,将显示您可以使用哪些其他宏值。
因为我不太知道您想要达到什么级别,以及您希望构建的复杂程度,这可能会给您一些想法。 我最近一直在做构建脚本,甚至在构建过程中执行 SQL 代码。 如果您需要更多帮助,甚至需要一些示例构建脚本,请告诉我,但如果这只是您想在构建结束时运行的一个小进程,那么使用完整的 msbuild 脚本可能有点过头了。
希望能帮助到你
日韩
Would it not make sense to use msbuild directly? If you are doing this with every build, then you can add a msbuild task at the end? If you would just like to see if you can’t find another macro value that is not showed on the Visual Studio IDE, you could switch on the msbuild options to diagnostic and that will show you all of the variables that you could use, as well as their current value.
To switch this on in visual studio, go to Tools/Options then scroll down the tree view to the section called Projects and Solutions, expand that and click on Build and Run, at the right their is a drop down that specify the build output verbosity, setting that to diagnostic, will show you what other macro values you could use.
Because I don’t quite know to what level you would like to go, and how complex you want your build to be, this might give you some idea. I have recently been doing build scripts, that even execute SQL code as part of the build. If you would like some more help or even some sample build scripts, let me know, but if it is just a small process you want to run at the end of the build, the perhaps going the full msbuild script is a bit of over kill.
Hope it helps
Rihan
我通过重新安装 VS 然后下载 .Net Core(3.x 和 2.x)sdk 包解决了我的问题
I solved my problem by reinstall VS and then download .Net Core (3.x and 2.x) sdk packages
这是我的构建后脚本
脚本:
Here is my post build script
script: