简体   繁体   English

如何将未编译的内容与通过Visual Studio发布的C#程序一起包含在内

[英]How to include non-compiled content alongside a C# program published via Visual Studio

I'm trying to publish an XNA game through the Visual Studio Publish tool. 我正在尝试通过Visual Studio发布工具发布XNA游戏。 The game uses some compiled and some non-compiled content. 游戏使用一些编译和一些非编译的内容。 Basically, I have a level loaded in via XML serialization and a short video. 基本上,我通过XML序列化和短视频加载了一个级别。 These two files are essentially streamed in, so they aren't compiled. 这两个文件基本上是流式传输的,因此它们不会被编译。 The publish tool includes the compiled content fine, but any references to relative paths are broken because the CurrentDirectory for installed programs are set in the AppData folder. 发布工具包含已编译的内容,但是对相对路径的任何引用都会被破坏,因为已安装程序的CurrentDirectory是在AppData文件夹中设置的。

I know that XNA can now compile XML without having to write custom content processors, but I don't particularly want to go back to rewrite that. 我知道XNA现在可以编译XML而无需编写自定义内容处理器,但我不想特别想重新编写它。 I suppose I can if there's no other option, but that still doesn't remedy the video problem. 我想我可以,如果没有其他选择,但仍然无法解决视频问题。

Is there any way to set up the publish tool so that I can do what I need to do? 有没有办法设置发布工具,以便我可以做我需要做的事情? A setting or something? 设置还是什么? Or will I need to use a more fully-featured tool like NSIS? 或者我需要使用像NSIS这样功能更全面的工具吗?

Right click project, Add Existing Resource, browse and select the file you want to add. 右键单击项目,添加现有资源,浏览并选择要添加的文件。 Then right click the file and click properties and change "Build Action" to content, and "Copy To Output Directory" to Copy if newer (or copy always if the need be). 然后右键单击该文件并单击属性并将“构建操作”更改为内容,将“复制到输出目录”更改为“如果更新则复制”(或者如果需要则始终复制)。 Then you can access it by using the relative path. 然后,您可以使用相对路径访问它。

I use this for my XML and I can access my content using the following code: 我将它用于我的XML,我可以使用以下代码访问我的内容:

XmlDocument document = new XmlDocument();
document.Load("Resources/DefaultConfig.xml");

Please note that my DefaultConfig.xml file is inside a "Resoruces" Directory which I created in Visual Studio(this is optional, but it helps me keep my project neat) 请注意我的DefaultConfig.xml文件位于我在Visual Studio中创建的“Resoruces”目录中(这是可选的,但它可以帮助我保持项目整洁)

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

相关问题 如何从Windows C#(Visual Studio)运行cygwin编译的程序? - How do you run a cygwin-compiled program from windows c# (visual studio)? 如何在已发布的 c# Visual Studio 构建中按路径引用文件 - how to reference file by path in published c# visual studio build 非编译项目中的代码重用 - Code reuse in non-compiled project 已发布程序上的 NullReferenceException 但在 Visual Studio 中没有 - NullReferenceException on published program but not in Visual Studio C#-Visual Studio在运行时崩溃,在外部运行已编译程序的效果很好 - C# - Visual Studio crashes at runtime, running the compiled program externally works fine 如何在不依赖Visual Studio C#的生成中包含项目 - How to include a project in a build that is not a dependency in Visual Studio c# 如何在 Visual Studio、C# 项目的部署中包含文件和文件夹? - How to include files and folders in the deployment of a visual studio, C# project? 如何在C#/ Visual Studio中包含源而不是库? - How to include source instead of a library in C# / Visual Studio? Linq查询性能,比较已编译查询和未编译查询 - Linq Query Performance , comparing Compiled query vs Non-Compiled 如何在 Visual Studio Code 中将 DLL 添加到 C# 程序中? - How to add a DLL to a C# program in Visual Studio Code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM