Possible problem publishing content with ClickOnce in XNA Game Studio 3.0 or 3.1

I ran into an issue in a Creators Club forum post this week that I wanted to describe in more detail here in case anyone runs into a similar issue in the future.

In the forum post, a developer was using the animated sprite sample available in this MSDN topic as the starting point for a project, then adding some items to the content project.  Afterwards, they tried to use the Publish command to create a ClickOnce deployment package.  Installing the ClickOnce package on another machine completed, but the game would not run because the content was not deployed along with the game binaries.

I looked at the project files included in this sample and found that the .csproj file for the Windows game is missing some metadata that is required by the ClickOnce publishing process in XNA Game Studio 3.0 and XNA Game Studio 3.1.  The Windows game .csproj includes the following ItemGroup that references the nested content project:

<ItemGroup>
  <NestedContentProject Include="Content\Content.contentproj">
    <ContentRootPath>Content</ContentRootPath>
    <Visible>False</Visible>
  </NestedContentProject>
</ItemGroup>

XNA Game Studio 3.0 and 3.1 includes logic to automatically include the content in each nested content project in the ClickOnce publishing output.  This logic requires each NestedContentProject element in the .csproj to include a Project child element.  The Project element must be set to a GUID value that exactly matches the value of the ProjectGuid element in the .contentproj file for the content project (including the curly braces - if the GUID has curly braces in the game project, it must also have curly braces in the content project and vice versa).

In the animated sprite sample referenced above, this would look like the following:

<ItemGroup>
  <NestedContentProject Include="Content\Content.contentproj">
    <Project>8ebb2a4c-cb7d-46a7-94a2-82f45c712d12</Project>
    <ContentRootPath>Content</ContentRootPath>
    <Visible>False</Visible>
  </NestedContentProject>
</ItemGroup>

After adding the Project element listed in bold above to the Windows game .csproj file in the animated sprite sample, the Publish command will correctly include items that are in the game’s content project when creating a ClickOnce deployment package.

The built-in XNA Game Studio project templates include this Project element by default and set it to the correct GUID value when you instantiate a new project.  Unfortunately, some of the older samples that we created in pre-3.0 versions of XNA Game Studio did not have that element, so it may be necessary to manually fix the .csproj by adding this information if you are discover that the files in your content project(s) are failing to deploy when using ClickOnce publishing.

One note here – it is possible to invoke the ClickOnce Publish command in XNA Game Studio Express 1.0 and XNA Game Studio 2.0 projects, but the command will not work correctly in those versions of XNA Game Studio.  If you are running into issues with ClickOnce with older versions of XNA Game Studio, you should upgrade to at least XNA Game Studio 3.0 and try again first.  If you still run into issues, check to make sure your project has the above metadata.  If that isn’t the issue either, please contact me and/or post a question on the Creators Club Forums and we’ll be able to help you investigate further.

<update date="7/14/2009"> Updated post to indicate that this issue can affect XNA Game Studio 3.0 and 3.1, not just 3.0. </update>

<update date="5/27/2010"> Added a note about curly braces around the project GUID because I ran into a publishing issue recently where content was not published when the GUID in the content project was surrounded by curly braces but the GUID in the NestedContentProject section of the game project was not. </update>