Nez icon indicating copy to clipboard operation
Nez copied to clipboard

ContentPathGenerator.tt keeps the extension when it's not needed

Open equalisysdev opened this issue 5 months ago • 4 comments

I got a structure that looks like this

Root
|    ContentPathGenerator.tt
|    Content
     |    textures
          |    logo
               |    studio
                   |    black.png
| ...

so the template generates something like this:

class Content
	{
		public static class Textures
		{
			public static class Logo
			{
				public static class Studio
				{
					public const string Black = @"Content\textures\logo\studio\black.png";
				}

			}

			public const string Ball = @"Content\textures\ball.png";
		}

		public const string Content = @"Content.mgcb";

	}
}

But when I use it, i get an error : FileNotFoundException : Could not find file '[...]\bin\Debug\net8.0\Content\textures\logo\studio\black.png.xnb'.

Because the real file path is [...]\bin\Debug\net8.0\Content\textures\logo\studio\black.xnb

The file extension is removed at Content compile time but the template doesn't seem to take that into account..

How could it be fixed?

equalisysdev avatar Aug 10 '25 13:08 equalisysdev

I found somewhat of a fix for this.. in PrintContentFiles, just before the WriteLine, i put

			finalPath = finalPath.Substring(0, finalPath.IndexOf(".") + 1);
			finalPath = finalPath.Replace(".", string.Empty);

so it removes everything after the first "." it finds... The problem is if your file has a "." in the name that is not the extension

equalisysdev avatar Aug 10 '25 13:08 equalisysdev

Nez doesnt generally use XNB files for textures. You can load the PNG directly via the NezContentManager and the usual png extension.

prime31 avatar Aug 10 '25 18:08 prime31

Nez doesnt generally use XNB files for textures. You can load the PNG directly via the NezContentManager and the usual png extension.

That's what I think I do but I'm not sure if I do it correctly Here is the code :

var logoTexture = Content.Load<Texture2D>(Nez.ContentPath.Textures.Logo.Studio.Black);

equalisysdev avatar Aug 12 '25 11:08 equalisysdev

you should use Content.LoadTexture()

optimo avatar Aug 25 '25 18:08 optimo