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

Building Xbox 360 Custom Class Library

Last post 03-31-2008 3:44 PM by Nick Gravelyn. 4 replies.
  • 03-31-2008 3:21 PM

    Building Xbox 360 Custom Class Library

    I built a custom class library for my game and it works just fine with any projects that I build in the Windows environment, but if I add it into an Xbox 360 project and try and use it my program will break.  Right now I just tried it and I get 139 errors in my program.  Here is an example error:

    Error    1    The type 'Microsoft.Xna.Framework.PlayerIndex' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Xna.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d'.    C:\Documents and Settings\Jonathan.berube\Desktop\Shoot\Shoot\ShootGame.cs    139    17    Shoot360

    Here is the Code Block that the error references:

    PlayerController[] controllers = new PlayerController[4];
    for (int a = 0; a < 4; a++)
    {
        controllers[ a ] = new PlayerController((PlayerIndex)a);
    }


    Here is the constructor for my class:

    public PlayerController(PlayerIndex index)


    The namespace for the PlayerController is Shoot.Logic.Actors.Behaviors, and the ShootGame.cs references this in the using block.  I have both in the Logic Class Library project and in the Shoot360 project both:
    Microsoft.Xna.Framework
    Microsoft.Xna.Framework.Game

    In the 360 solution I also have added the reference
    Logic.

    Again the same exact code compiles in Windows, but it will not compile for Xbox 360.  I also tried removing my Xbox 360 project and creating a new copy from the Windows project and it does not work. 
  • 03-31-2008 3:35 PM In reply to

    Re: Building Xbox 360 Custom Class Library

    The XNA references on the 360 and windows are different.

    So when you build a class library you need to make 2 projects for it - one with windows references and one with Xbox references. Then from the windows version of your game you reference the windows class library and from the xbox version of your game you reference the xbox version of your library. You can't make a single library and reference from both...



    The ZBuffer News and information for XNA

    Please read the forum FAQs - Bug reporting
  • 03-31-2008 3:40 PM In reply to

    Re: Building Xbox 360 Custom Class Library

    Windows and XBox use two different sets of XNA assemblies. You need to build the library against the Xbox assemblies to use them in an Xbox project.

    Create a new class library project, and add the source files from the existing project to this one (add them as links. Add Existing Item, then in the dialog pick the files, on the Add button click the little arrow and select to add them as links).

    In the new library, reference the Xbox assemblies, they are at

    c:\Program Files\Microsoft XNA\XNA Game Studio\v2.0\References\Xbox 360

    So right click on references, select "Add Reference", then in the dialog go to the browse tab, and find the Xbox assemblies at the location I included above.

  • 03-31-2008 3:42 PM In reply to

    Re: Building Xbox 360 Custom Class Library

    I see why it did not work before.  I was using the base Visual C# > Class Library instead of the Visual C# > XNA Game Studio > Windows Game Library ( or Xbox 360 Game Library ).

    Thanks.
  • 03-31-2008 3:44 PM In reply to

    Re: Building Xbox 360 Custom Class Library

    Matt:
    In the new library, reference the Xbox assemblies, they are at

    c:\Program Files\Microsoft XNA\XNA Game Studio\v2.0\References\Xbox 360

    So right click on references, select "Add Reference", then in the dialog go to the browse tab, and find the Xbox assemblies at the location I included above.



    Even if you make a new project, you don't have to browse for them. In the Xbox 360 project when you open the Add Reference tab, it only shows valid Xbox 360 references in the .NET tab. So you can just pick them out of there rather than browsing down.

    Glad to hear you got it sorted out. Yes, you want to make sure to use the XNA library projects to take care of all the references for you.
Page 1 of 1 (5 items) Previous Next