简体   繁体   English

在Visual Studio中处理简单C ++项目的图像和声音文件

[英]Handling images and sound files for a simple C++ project in Visual Studio

I am new to Visual Studio, and I am trying to figure out the best way to organize my projects. 我是Visual Studio的新手,我正在努力找出组织项目的最佳方法。

I am writing an application using the sfml library, and I have various resources (images/sounds) that I am using. 我正在使用sfml库编写应用程序,并且我使用了各种资源(图像/声音)。 I dropped these into the project folder, and everything works fine when I launch my application from Visual Studio. 我把它们放到项目文件夹中,当我从Visual Studio启动我的应用程序时,一切正常。

I am wondering though, how does this translate to when a program is deployed? 我想知道,这是如何转换为部署程序的? If I go into my solution's debug folder, and try launching the exe, it is unable to locate any of the resource files. 如果我进入我的解决方案的调试文件夹,并尝试启动exe,它将无法找到任何资源文件。 Am I suppose to tell Visual Studio to copy files to an appropriate directory, and if so how? 我想告诉Visual Studio将文件复制到适当的目录,如果是这样,怎么办?

Thanks for any advice or links. 感谢您的任何建议或链接。

for my project, I direct everything into one directory. 对于我的项目,我将所有内容都指向一个目录。
Go to ur project configuration, change General->Output directory , General->intermediate directory , and Debugging->Working directory to one directory. 转到您的项目配置,将General->Output directoryGeneral->intermediate directoryDebugging->Working directory更改为一个目录。 The reason you cannot locate the resource files is because the debug directory is not the same as the output directory. 无法找到资源文件的原因是调试目录与输出目录不同。

For slightly more complicated "deployment" scenario, you can use post-build scripts to copy the correct files into the output directory and even package it into a zip file, for example. 对于稍微复杂的“部署”方案,您可以使用构建后脚本将正确的文件复制到输出目录中,甚至将其打包到zip文件中。

If you find yourself writing more than one page of batch you may want to consider the options below, because batch is a PITA to debug. 如果您发现自己编写了多个批处理页面,则可能需要考虑以下选项,因为批处理是要调试的PITA。

Recent MSVS project files are actually MSBuild files (just open the .vcxproj file in Notepad or Vim). 最近的MSVS项目文件实际上是MSBuild文件(只需在记事本或Vim中打开.vcxproj文件)。 For instance you can use the Copy task , invoke arbitrary programs using the Exec task , etc. It can be a bit more sophisticated than the batch script in post-build scripts. 例如,您可以使用Copy任务 ,使用Exec任务调用任意程序等。它可能比后构建脚本中的批处理脚本更复杂。 MSBuild 4 can use Property Functions making it quite expressive. MSBuild 4可以使用属性函数使其具有很强的表现力。 Useful reference if you do this 如果你这样做,有用的参考

For a "full blown" project, you'll want to roll a dedicated build system using a dedicated MSBuild file, NAnt or even higher level wrappers like Rake . 对于“完整的”项目,您将需要使用专用的MSBuild文件, NAnt甚至更高级别的包装器(如Rake)来 推送专用的构建系统。

As a less popular alternative, in a previous project I built a small dedicated "builder" .exe project in the solution and have other projects depend on it. 作为一个不太受欢迎的替代方案,在之前的项目中,我在解决方案中构建了一个小的专用“构建器”.exe项目,并且其他项目依赖于它。 Then in the post-build scripts of the other projects I just invoke the builder projects with arguments to make it perform certain tasks. 然后在其他项目的后期构建脚本中,我只使用参数调用构建器项目以使其执行某些任务。 The advantage is that you can write C# (or F# or VB.NET) and not have to fight the build system (as much) and I think it works quite well for small-mid sized projects. 优点是你可以编写C#(或F#或VB.NET)而不必打造构建系统(同样多),我认为它适用于中小型项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM