Visual Studio 构建后事件 - 复制到相对目录位置

发布于 2024-07-19 17:42:32 字数 556 浏览 7 评论 0原文

成功构建后,我希望将输出目录的内容复制到同一“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

笙痞 2024-07-26 17:42:32

以下是您想要放入项目的构建后事件命令行中的内容:

copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)lib\$(ProjectName).dll"

编辑:或者如果您的目标名称与项目名称不同。

copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)lib\$(TargetName).dll"

Here is what you want to put in the project's Post-build event command line:

copy /Y "$(TargetDir)$(ProjectName).dll" "$(SolutionDir)lib\$(ProjectName).dll"

EDIT: Or if your target name is different than the Project Name.

copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)lib\$(TargetName).dll"
鱼窥荷 2024-07-26 17:42:32

如果 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

岁月流歌 2024-07-26 17:42:32

你可以尝试:

$(SolutionDir)..\..\

You could try:

$(SolutionDir)..\..\
記憶穿過時間隧道 2024-07-26 17:42:32

我认为这是相关的,但是当我直接使用 msbuild 命令行(从批处理文件)构建与从 VS 中构建时遇到了问题。

使用类似以下内容:

<PostBuildEvent>
  MOVE /Y "$(TargetDir)something.file1" "$(ProjectDir)something.file1"
  start XCOPY /Y /R "$(SolutionDir)SomeConsoleApp\bin\$(ConfigurationName)\*" "$(ProjectDir)App_Data\Consoles\SomeConsoleApp\"
</PostBuildEvent>

(注意: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:

<PostBuildEvent>
  MOVE /Y "$(TargetDir)something.file1" "$(ProjectDir)something.file1"
  start XCOPY /Y /R "$(SolutionDir)SomeConsoleApp\bin\$(ConfigurationName)\*" "$(ProjectDir)App_Data\Consoles\SomeConsoleApp\"
</PostBuildEvent>

(note: start XCOPY rather than XCOPY used to get around a permissions issue which prevented copying)

The macro $(SolutionDir) evaluated to ..\ when executing msbuild from a batchfile, which resulted in the XCOPY 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.

梦晓ヶ微光ヅ倾城 2024-07-26 17:42:32

直接使用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

趁年轻赶紧闹 2024-07-26 17:42:32

我通过重新安装 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

月光色 2024-07-26 17:42:32

这是我的构建后脚本

  1. 为我自己创建自定义路径。 包括库和版本。
  2. 复制 .dll(目标文件)
  3. 复制 *.md 文件。

脚本:

md c:\_References\$(ProjectName)\$(AssemblyVersion)
xcopy $(ProjectDir)$(OutDir)$(TargetFileName) c:\_References\$(ProjectName)\$(AssemblyVersion) /y
xcopy $(ProjectDir)*.md c:\_References\$(ProjectName)\$(AssemblyVersion) /y

Here is my post build script

  1. Creates the custom path for my own. Including library and version.
  2. Copies the .dll (target file)
  3. Copies the *.md files.

script:

md c:\_References\$(ProjectName)\$(AssemblyVersion)
xcopy $(ProjectDir)$(OutDir)$(TargetFileName) c:\_References\$(ProjectName)\$(AssemblyVersion) /y
xcopy $(ProjectDir)*.md c:\_References\$(ProjectName)\$(AssemblyVersion) /y
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文