如何包含“内容" Windows 8.1 Phone中子目录中的文件? [英] How do I include "content" files in subdirectories in Windows 8.1 Phone?

查看:95
本文介绍了如何包含“内容" Windows 8.1 Phone中子目录中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个文件很多的项目(一个游戏).这些文件可以从VS 2013外部进行更改,例如由艺术家.这些文件位于子目录中,我们的游戏期望它们存在于这些子目录中.例如images/items/block.png

我尝试使用构建后事件

xcopy /C /Y /I /R /S /Q "$(SolutionDir)game_data\*" "$(TargetDir)"

,以及$(LayoutDir).在我的桌面(Windows RT Store)项目上不会发生此问题,因为我只是将文件复制到内部版本的AppX目录中,当我运行该文件时,exe会找到它们.但是,使用Windows Phone时,不再有AppX目录,并且不会将其复制到Phone.

如何将$(SolutionDir)game_data中的文件和目录包含到已在手机上安装的软件包中?

最好是以下解决方案:

  • 不必在项目过滤器中重新创建整个子文件夹结构
  • 不必在属性中为以下文件中的每个文件指定"Content = Yes" 每个子目录.
  • 不必添加或删除由艺术家添加到目录中的任何新文件.

解决方案

您需要尽早复制文件,以使它们包含在Appx软件包中.您将在构建后的桌面上复制到Appx目录的解决方案仅限于构建计算机,该计算机直接在其自己的文件夹中运行该应用程序,而不进行完全部署.由于这些文件不在部署包中,因此它们在其他系统上将不可用.这在电话上更为明显,因为您始终需要在运行它之前部署该应用程序,但这最终是同一回事.

手动方法是将文件包括在Visual Studio项目中.您可以将文件复制到项目目录,显示所有文件,然后选择并包括新文件.如果没有将它们自动添加为内容"(示例中的大多数图像类型都为png),则需要对其进行显式设置,以便在构建时将其包含在appxpackage中.

这几乎是您所说的不想要的情况.

相反,您可以自动将项目添加到项目文件中. vcxproj文件是XML文件(此处的方案),您可以编写脚本将资产文件添加到项目中的 ItemGroups 并对其进行标记作为DeploymentContent:

<ItemGroup>
    <Image Include="images\items\block.png" />
    <None Include="Assets\frotz.foo">
        <DeploymentContent>true</DeploymentContent>
    </None>
    <None Include="Assets\wibble.foo">
        <DeploymentContent>true</DeploymentContent>
    </None>
</ItemGroup>

最后,您可以使用makeappx.exe自己创建appxpackage,而不是让Visual Studio为您完成.这样,您就可以完全控制包中的文件,包括从VS项目外部拉入文件的功能.请参见应用程序包和部署应用程序包(MakeAppx.exe)文档.

I'm working on a project with a lot of files (a game). These files can change from outside VS 2013, e.g. by artists. The files are located in subdirectories and our game expects them there. For instance images/items/block.png

I've tried using a post-build event

xcopy /C /Y /I /R /S /Q "$(SolutionDir)game_data\*" "$(TargetDir)"

and also with $(LayoutDir). The problem does not occur on our Desktop (Windows RT Store) project because I just copy the files to the build's AppX directory and when I run, the exe finds them. But with Windows Phone there is NO AppX directory anymore and it DOESN't copy it to the Phone.

How do I include files AND directories from $(SolutionDir)game_data into the package that gets installed on the phone?

Preferably a solution where I:

  • Do not have to recreate the entire sub folder structure in the Project filters
  • Do not have to specify "Content=Yes" in the properties for each file in each subdirectory.
  • Do not have to add or remove any new files that get added to the directory by artists.

解决方案

You'll need to copy the files early enough that they get included in the Appx package. Your solution of copying to the Appx directory post-build on the desktop is limited to the build machine which runs the app directly out of its own folder rather than doing a full deployment. Since the files aren't in the deployment package they won't be available on other systems. This is more obvious on the phone since you'll always need to deploy the app before running it, but it is ultimately the same thing.

The manual way is to include the files in the Visual Studio project. You can copy the files to the project directory, show all files, and then select and include the new files. If they aren't automatically added as Content (most image types like the png in your example will be) then you'll need to set that explicitly so that they are included in the appxpackage when built.

This is pretty much the scenario you said you didn't want.

Instead you can automate adding the items to the project file. The vcxproj file is an XML file (scheme here) and you can write a script to add your asset files to ItemGroups in the project and flag them as DeploymentContent:

<ItemGroup>
    <Image Include="images\items\block.png" />
    <None Include="Assets\frotz.foo">
        <DeploymentContent>true</DeploymentContent>
    </None>
    <None Include="Assets\wibble.foo">
        <DeploymentContent>true</DeploymentContent>
    </None>
</ItemGroup>

Lastly, you can create the appxpackage yourself with makeappx.exe rather than letting Visual Studio do it for you. This will let you have full control over the files in the package, including the ability to pull them in from outside of the VS project. See App packages and deployment and the App package (MakeAppx.exe) documentation.

这篇关于如何包含“内容" Windows 8.1 Phone中子目录中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆