XNA Creators Club Online
Page 1 of 1 (8 items)
Sort Posts: Previous Next

Content not found with ClickOnce deployment

Last post 04/06/2009 17:26 by Aaron Stebner. 7 replies.
  • 30/05/2009 0:22

    Content not found with ClickOnce deployment

    Ok, once again a content problem.  When I run my game within the IDE, it loads the content and everything runs fine.  I tried using ClickOnce deployment, but it failed to install on my machine and a friend's and I figured out through the debugger that it was not finding my .png file.  Here is the code.  There are 3 cs files:

    AnimatedTexture.cs
    // AnimatedTexture.cs 
    // 
    // Microsoft XNA Community Game Platform 
    // Copyright (C) Microsoft Corporation. All rights reserved. 
    //----------------------------------------------------------------------------- 
    #endregion 
     
    using System; 
    using System.Collections.Generic; 
    using Microsoft.Xna.Framework; 
    using Microsoft.Xna.Framework.Content; 
    using Microsoft.Xna.Framework.Graphics; 
    using Microsoft.Xna.Framework.Input; 
     
    namespace AnimatedSprite 
        public class AnimatedTexture 
        { 
            private int framecount; 
            private Texture2D myTexture; 
            private float TimePerFrame; 
            private int Frame; 
            private float TotalElapsed; 
            private bool Paused; 
     
            public float Rotation, Scale, Depth; 
            public Vector2 Origin; 
            public AnimatedTexture(Vector2 origin, float rotation, float scale, float depth) 
            { 
                this.Origin = origin; 
                this.Rotation = rotation; 
                this.Scale = scale; 
                this.Depth = depth; 
            } 
            public void Load(ContentManager content, string asset, int frameCount, int framesPerSec) 
            { 
                framecount = frameCount; 
                myTexture = content.Load<Texture2D>(asset); 
                TimePerFrame = (float)1 / framesPerSec; 
                Frame = 0; 
                TotalElapsed = 0; 
                Paused = false
            } 
     
            // class AnimatedTexture 
            public void UpdateFrame(float elapsed) 
            { 
                if (Paused) 
                    return
                TotalElapsed += elapsed; 
                if (TotalElapsed > TimePerFrame) 
                { 
                    Frame++; 
                    // Keep the Frame between 0 and the total frames, minus one. 
                    Frame = Frame % framecount; 
                    TotalElapsed -= TimePerFrame; 
                } 
            } 
     
            // class AnimatedTexture 
            public void DrawFrame(SpriteBatch batch, Vector2 screenPos) 
            { 
                DrawFrame(batch, Frame, screenPos); 
            } 
            public void DrawFrame(SpriteBatch batch, int frame, Vector2 screenPos) 
            { 
                int FrameWidth = myTexture.Width / framecount; 
                Rectangle sourcerect = new Rectangle(FrameWidth * frame, 9, 
                    FrameWidth, myTexture.Height -9); 
                batch.Draw(myTexture, screenPos, sourcerect, Color.White, 
                    Rotation, Origin, Scale, SpriteEffects.None, Depth); 
            } 
     
            public bool IsPaused 
            { 
                get { return Paused; } 
            } 
            public void Reset() 
            { 
                Frame = 0; 
                TotalElapsed = 0f; 
            } 
            public void Stop() 
            { 
                Pause(); 
                Reset(); 
            } 
            public void Play() 
            { 
                Paused = false
            } 
            public void Pause() 
            { 
                Paused = true
            } 
     
        } 
     

    Game1.cs
    #region File Description 
    //----------------------------------------------------------------------------- 
    // Game1.cs 
    // 
    // Microsoft XNA Community Game Platform 
    // Copyright (C) Microsoft Corporation. All rights reserved. 
    //----------------------------------------------------------------------------- 
    #endregion 
     
    using System; 
    using System.Collections.Generic; 
    using Microsoft.Xna.Framework; 
    using Microsoft.Xna.Framework.Content; 
    using Microsoft.Xna.Framework.Graphics; 
    using Microsoft.Xna.Framework.Input; 
     
    namespace AnimatedSprite 
        /// <summary> 
        /// This is the main type for your game 
        /// </summary> 
        public class Game1 : Microsoft.Xna.Framework.Game 
        { 
            GraphicsDeviceManager graphics; 
            SpriteBatch spriteBatch; 
     
            private AnimatedTexture SpriteTexture; 
            private const float Rotation = 0; 
            private const float Scale = 1.0f; 
            private const float Depth = 0.5f; 
            public Game1() 
            { 
                graphics = new GraphicsDeviceManager(this); 
                Content.RootDirectory = "Content"
                SpriteTexture = new AnimatedTexture(Vector2.Zero, Rotation, Scale, Depth); 
    #if ZUNE 
                // Frame rate is 30 fps by default for Zune. 
                TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0); 
    #endif 
            } 
     
            /// <summary> 
            /// Allows the game to perform any initialization it needs to before starting to run. 
            /// This is where it can query for any required services and load any non-graphic 
            /// related content.  Calling base.Initialize will enumerate through any components 
            /// and initialize them as well. 
            /// </summary> 
            protected override void Initialize() 
            { 
                // TODO: Add your initialization logic here 
     
                base.Initialize(); 
            } 
     
            private Viewport viewport; 
            private Vector2 shipPos; 
            private const int Frames = 15; 
            private const int FramesPerSec = 6; 
            protected override void LoadContent() 
            { 
                // Create a new SpriteBatch, which can be used to draw textures. 
                spriteBatch = new SpriteBatch(GraphicsDevice); 
     
                // "shipanimated" is the name of the sprite asset in the project. 
                SpriteTexture.Load(Content, "Sneak", Frames, FramesPerSec); 
                viewport = graphics.GraphicsDevice.Viewport; 
                shipPos = new Vector2(viewport.Width / 2, viewport.Height / 2); 
            } 
     
            /// <summary> 
            /// UnloadContent will be called once per game and is the place to unload 
            /// all content. 
            /// </summary> 
            protected override void UnloadContent() {} 
     
            protected override void Update(GameTime gameTime) 
            { 
                // Allows the game to exit 
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
                    this.Exit(); 
     
                // Pauses and plays the animation. 
                if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed) 
                { 
                    if (SpriteTexture.IsPaused) 
                        SpriteTexture.Play(); 
                    else 
                        SpriteTexture.Pause(); 
                } 
                float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds; 
     
                // TODO: Add your game logic here. 
                SpriteTexture.UpdateFrame(elapsed); 
                base.Update(gameTime); 
            } 
     
            /// <summary> 
            /// This is called when the game should draw itself. 
            /// </summary> 
            /// <param name="gameTime">Provides a snapshot of timing values.</param> 
            protected override void Draw(GameTime gameTime) 
            { 
                GraphicsDevice.Clear(Color.CornflowerBlue); 
     
                // TODO: Add your drawing code here 
                spriteBatch.Begin(); 
                SpriteTexture.DrawFrame(spriteBatch, shipPos); 
                spriteBatch.End(); 
     
                base.Draw(gameTime); 
            } 
        } 
     
     
     

    Program.cs
    #region File Description 
    //----------------------------------------------------------------------------- 
    // Program.cs 
    // 
    // Microsoft XNA Community Game Platform 
    // Copyright (C) Microsoft Corporation. All rights reserved. 
    //----------------------------------------------------------------------------- 
    #endregion 
     
    using System; 
     
    namespace AnimatedSprite 
        static class Program 
        { 
            /// <summary> 
            /// The main entry point for the application. 
            /// </summary> 
            static void Main(string[] args) 
            { 
                using (Game1 game = new Game1()) 
                { 
                    game.Run(); 
                } 
            } 
        } 

    The properties for the .png file are as follows:
    Build Action: Compile
    Copy to Output Directory: Do not copy (I tried setting this to copy always, but it still didn't work)
    Asset name: Sneak
    Content Importer: Texture
    Content Processor: Texture with default sub properties

    Any help would be much appreciated.  Thanks.

  • 02/06/2009 22:31 In reply to

    Re: Content not found with ClickOnce deployment

    Is your .png file included in your content project, or did you add it to your code project?  If it is in the content project, it should be picked up automatically by the ClickOnce publishing command.  If it is in the code project, you need to make sure to set the attributes appropriately to cause them to be published.

    There is a note in the "Special Considerations for Game Data Files" section of the documentation topic at http://msdn.microsoft.com/en-us/library/bb464156.aspx that explains how to set the attributes for files like this if they aren't in the content project.

    If it is in the content project, can you try to deploy it to another computer and then look in the ClickOnce folder that gets created to see if the file ends up on the target system?

    Thanks!

  • 03/06/2009 3:12 In reply to

    Re: Content not found with ClickOnce deployment

    Hey Aaron, thank you for the reply.  Yes, I have added the .png file to the content project.  I can send you my project if you like.  If you could take a look I would very much appreciate it.  I have been trying to get this to work for almost a week.
  • 03/06/2009 3:24 In reply to

    Re: Content not found with ClickOnce deployment

    If you can zip up your project directory (the .csproj, the code files, the Content directory, etc) and post it on a file server, I can download it and take a look to see if I can figure anything out here.  I would need to be able to build and publish the project on my side, so please make sure to include whatever files are in your project that are needed for that.  If you have any sensitive project code, please pull that code out and create a more minimal project instead if possible.

    Thanks!
  • 03/06/2009 18:48 In reply to

    Re: Content not found with ClickOnce deployment

    Thanks Aaron.  I've got the full project posted to Media Fire at http://www.mediafire.com/?sharekey=90942cba74b4da4c0c814df2efeadc50e04e75f6e8ebb871
  • 04/06/2009 0:33 In reply to

    Re: Content not found with ClickOnce deployment

    Thanks for posting the project.  The Publish command wasn't including the files in your .contentproj at all.  There is a key piece of metadata missing from your .csproj that is causing this.  In your original Windows .csproj, the .contentproj is referenced like this:

     

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

    The built-in XNA Game Studio project templates reference .contentproj files like this:

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

    The GUID in the <Project> element above has to match the <ProjectGuid> value at the top of your .contentproj file.  When I added the text in bold to the project you sent me, the Publish command started correctly including the files in your .contentproj.

    It shouldn't be possible for your .csproj to be missing this item if you're creating the project from one of the XNA Game Studio templates.  It looks like your project is based on one of the samples we published on the Creators Club site though, and unfortunately some of those samples were not created from XNA Game Studio templates, and as a result they are missing meta-data that is needed for some scenarios like this.  I will open a bug to get this sample fixed in the future.  In the meantime, you'll need to use the above workaround if you want to be able to use the Publish command for this project.

    Thanks!

     

  • 04/06/2009 2:03 In reply to

    Re: Content not found with ClickOnce deployment

    It works!!!  Thanks Aaron, I really appreciate you taking the time to help me out.  BTW, I got the initial project from the MSDN here.  Take care.
  • 04/06/2009 17:26 In reply to

    Re: Content not found with ClickOnce deployment

    I'm glad to hear that this workaround solved the problem you were running into.  Thanks for sending this link - I've reported a bug in our team's bug database to track fixing this in the future.

    Thanks!
Page 1 of 1 (8 items) Previous Next