我有一个c++ Visual Studio项目,依赖于一些资源(.glsl
文件)。
目前,每次构建项目时,我都必须复制并粘贴资源目录,但这很不方便。
我想知道是否有一种方法可以使构建过程自动包含资源文件生成的.exe
之外。如果有人能提供一些参考,我将不胜感激,因为我在网上找不到任何东西。
项目结构如下:
root
|
+-- resources
| |
| +- shaders
| |
| +- shader files (.glsl)
|
+- src files (.cpp/.h)
发布版本后的当前结果:
Release
|
+- .exe
+- .pdb
+- DLLs
预期的结果:
Release
|
+-- resources
| |
| +- shaders
| |
| +- shader files (.glsl)
|
+- .exe
+- .pdb
+- DLLs
编辑
根据Minxin Yu - MSFT的建议,我尝试使用Post-build事件,使用以下命令:
PowerShell Copy-Item -Path $(SolutionDir)$(ProjectName)resources -Destination $(SolutionDir)x64Release -Recurse
但是生成失败,出现以下错误:
Build started...
1>------ Build started: Project: 02es, Configuration: Release x64 ------
1>Copy-Item : Impossibile trovare un parametro posizionale che accetta l'argomento
1>'RighiProgrammiGitHubFondamenti-di-Computer-Graphics-Mlaboratorio 2esresources'.
1>In riga:1 car:1
1>+ Copy-Item -Path D:Michele RighiProgrammiGitHubFondamenti-di-Compu ...
1>+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1> + CategoryInfo : InvalidArgument: (:) [Copy-Item], ParameterBindingException
1> + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
1>
1>C:Program FilesMicrosoft Visual Studio2022CommunityMSBuildMicrosoftVCv170Microsoft.CppCommon.targets(149,5): error MSB3073: The command "PowerShell Copy-Item -Path D:Michele RighiProgrammiGitHubFondamenti-di-Computer-Graphics-Mlaboratorio 2esresources -Destination D:Michele RighiProgrammiGitHubFondamenti-di-Computer-Graphics-Mlaboratoriox64Release -Recurse
1>C:Program FilesMicrosoft Visual Studio2022CommunityMSBuildMicrosoftVCv170Microsoft.CppCommon.targets(149,5): error MSB3073: :VCEnd" exited with code 1.
1>Done building project "02es.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 9:23 AM and took 02,321 seconds ==========
在项目属性的构建事件中添加构建后事件。
。
PowerShell Copy-Item -Path $(SolutionDir)$(ProjectName)resources -Destination $(SolutionDir)x64Release -Recurse
更新:对于带有空格的路径,使用"one_answers">
PowerShell Copy-Item "-Path '$(SolutionDir)$(ProjectName)resources' -Destination '$(SolutionDir)x64Release' -Recurse"