Using XNA Content Pipeline in a C# Form - c#

I'm trying to create a game editor using a C# form, and I've run into a problem when it comes to deserializing; I can't use the content pipeline in a forms application as I don't even have the option to add any content reference to the project. How can I use the content pipeline with my form app? Is there another way to load and deserialize my XML content?

Manually edit the .csproj file and add the following in the first PropertyGroup section which contains the assembly name, project guid etc.
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
You'll probably need to also add
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<XnaPlatform>Windows</XnaPlatform>
Reload the project in VS, and you should be able to add content references to it.
The two GUIDs specified there are for Windows and XNA (Windows). Here is a list of some common project type guids (although slightly dated) if you need to retarget the project at all.

Take a look at the Winforms Series 2: Content Loading AppHub sample.
Basically you load and call appropriate microsoft.xna.framework.content classes to read your compiled xnb files.
You'd use classes in the namespaces within microsoft.xna.framework.content.pipeline to create the xnb files (which is what the content project would do for you).
See here for an overview of the content pipeline: What is the Content Pipeline?
Is there another way to load and deserialize my XML content?
Yes, use any .net method of serialising you want, maybe XDocument.

Related

Where to put resource file in web application

I am using resource file to manage strings to show in UI. I have requirement to show enum values to UI.
Definitely I can do it with [Display] attribute to achieve this. However i have common project for POCOs where i create Enums as well and to use display attribute, i would require to take resource project's reference in that POCOs project.
This causes resource file gets copied in every other projects who uses that POCOs including WCFs where it is not requried.
Any suggestion to achieve Displaying ENUM from Resource file but not let other projects to build Resource file DLL?

Code to add a C# class file to a project

Can anybody provide some code block to add an existing C# file to a project.
I have 2 projects in my solution. One project generates C# class files which will be use by second project. I have to incluse these generated files in the second project and build the project. It should be done through programatically. I know that to include these files I have to edit the C#project file (which is an XML) and make an entry that file. But I thought of
using existing code if anybody has it.
Thanks
You can ahve a look at the MsBuild.Engine namespace. It allows you to manipulate a csproj in a consistent way so you can oper the target project and add the reference programmatically.

how to attach javascript file and use them when built dll file

I have a solution contain one class library and one JavaScript file. I want build it into dll file and then call a function in that file.
If this is for a web project (which I'm assuming) why do you want to do it this way? Is this for deployment of your single library to others?
You need to embed this as a resource which wil lthen use ScriptResource.axd.
See:
http://msdn.microsoft.com/en-us/library/system.web.handlers.scriptresourcehandler.aspx

Reusing code in .NET website (app_code folder)

I need to use some classes inside the app_code folder of a website project in visual studio 2008. I need to access this code from a class library project in the same solution. I cannot add a reference to the website, and I'm not sure of the easiest way to use the classes that already exist here. Do I need to move it to a class library?
What other options do I have?
Yes, create a class library and move any types you need into that library. This library can be referenced in as many places as you would like.
The best way to do this is to put those classes in their own library.
However, if you really don't want to do that, you could add a link to the files in the library project. To do that, right-click the Class Library project or a folder within it, Add, Existing Item, navigate to the code files, click the down arrow near the Add button, Add As Link. This will add the same file to both projects. You can even use the #if preprocessor directive to limit portions of the file to specific projects.
However, it is vastly preferable to put the code in a library and reference it in the web project.

How to add a dependency to a arbitrary file to a T4 template?

I have a T4 template that generates classes from an xml file.
How can I add a dependency between the xml file and the template file so that when the xml file is modified the template is rerun automatically without choosing "Run custom tool" from the context menu?
I don't believe T4 supports automatic template transformation based on an external dependency. I agree with Marc - if you only have one external file, you could create a custom "custom tool" for your XML file or simply use ttxgen. However, I don't think this approach scales up to a scenario where t4 template depends on more than one file. You may need to create a Visual Studio package to handle that.
How long does the tool take to execute? One lazy option might be to simply edit the csproj such that it always runs the tool during build (presumably via <Exec ... /> or a custom targets file) - of course, this depends on it being quick to execute.
Another way would be to write a shim that works as the "Custom Tool" in VS, and simply calls the existing exe (or whatever) with the right args. Not trivial, but doable (see here) - I believe this then supposedly plays fairly nicely with change detection. It is actually on my list of things to do for a current project, so I'll find out soon enough...
You can use AutoTT Visual Studio Extension.
This extension allows to configure triggers that will run a T4 template.
One of the possible triggers is a file change. In the sample configuration file in AutoTT page, the regular expression for the triggers matches all files in the specified folders (Controllers, Content), but you can change it so that it runs with a specific file only.
Chirpy is another option for doing this. And also T4 Regenerator, which does it in a different way.
Have you tried using <## xsd?

Categories