Bloom326984

Hi there,

I am using a MSBuild project file to build some XNA content files. The files generated work perfectly fine. However, every single resultant .xnb file gets appended with '~0'. For example 'spark.bmp' generates a 'spark~0.xnb' file.

How can I either: prevent the MSBuild task from appending the file name, or to remove the '~0' after the file has been created.

By the way, is everyone else having this same thing happen

Thank you for your time



Re: Game Technolgies: XNA Build Removing '~0' from resultant file names

ProfEclipse

I'm not sure why you feel you need to "fix" this. Once the files are converted, you don't need to reference them by filename. Also, consider what happens if you have "spark.bmp" and "spark.x" in the same directory. Since they both become .xnb files, there has to be a way to prevent name clashes. Hence the "~0" that you are seeing.





Re: Game Technolgies: XNA Build Removing '~0' from resultant file names

Bloom

I am not using the typical 'Solution Explorer' method of building this .xnb files.

I am using a MSBuild script, which is called from an editor, to take a user specified list of image files and generate .xnb files. These resultant .xnb files are never manually added to the game project, rather they are copied by the MSBuild script to a specific 'Content' folder. This folder is then referenced by the game project to find the .xnb files needed. This is where I have my problem. The game, using the same user specified list of images as the editor, expects to find a file called 'Spark'. But since only 'Spark~0' exists, the game is unable to load the resource. An obvious solution to this, is for the game to automatically append '~0' to each file, but this is sloppy and I would prefer the type of solution I asked about earlier.

So, that being said, now that I have (hopefully) justified myself for asking such a question. Do you know how I can remove the '~0' via a MSBuild script Or is there a way to prevent the XNA Build Task from appending filenames I would expect the XNA Build Task to append something like this if there were 2 conflicting filenames, as you mentiond. But even when this is not the case, the appedning still occurs.

Thanks





Re: Game Technolgies: XNA Build Removing '~0' from resultant file names

Johnnylightbulb

I looked around for quite a while trying to fix this; it looks like the code in XNA always builds the ~0 part of the name, unless an AssetName is specifically given. Adding files to the GSE IDE does this, but building programmatically (and with BuildAsset<T, K>(ExternalReference<T>, string)) does not specifiy and AssetName. There is another overload with a couple strings that you won't know the values of, just pass null, null, "Spark" for the extra values and you'll have one properly named XNB when the build completes.

The only problem I've run into is that rebuilding Spark a number of times causes XNA to blow up because the XNB already exists. It would be nice if XNA let you see what has already been built so you could know this before requesting a build. It would also help if the Exception type wasn't so generic so you could catch this easily.

For my purposes, I think I'll inspect the message of the exception that gets thrown by keeping the expected exception text in my resource file.





Re: Game Technolgies: XNA Build Removing '~0' from resultant file names

Bloom

Thank you Johnny for looking into this. I will try the fix you found and let you know if it worked for me also.

As far as your 'rebuilding causes XNA to blow up' issue. I have had similar problems. Personally, I got around it by deleting the 'Bin' and 'Obj' folders that were generated by the BuildAsset task. My build script does this automatically. There are downsides though, this prevents the BuildAsset task from being able to determine if a 'rebuild' is actually needed. This means every time my build script is run, it has to build 100% of the assets again, which makes for longer build times. I realize this solution I am using isn't very pretty, but it works for now I guess =/

Thank you again





Re: Game Technolgies: XNA Build Removing '~0' from resultant file names

Wotan9

What you can do to solve this problem (and what I did) is to extend the BuildContent class :

public class MemoriesBuildContent : BuildContent, ITask
{
public override bool Execute()
{
bool success = base.Execute();

// Remove the ~0 of the files generated by base.Execute

return success;
}
}

Bloom, tell me if it helps you or if you need need further explanations.




Re: Game Technolgies: XNA Build Removing '~0' from resultant file names

Bloom

Thank you to the both of you. With your help I was able to get this resolved :)