Last active
August 17, 2021 08:43
-
-
Save tgjones/8c1c46e1950a7b9a4769 to your computer and use it in GitHub Desktop.
Automatically adding MonoGame XNBs into an assembly as Embedded Resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Replace the "BeforeBuild" target in your csproj with the XML above. | |
"ExtraContent" is defined in MonoGame.Content.Builder.targets. It contains the paths | |
to all the XNB files that have just been built by the MonoGame Content Pipeline. | |
The "LogicalName" mess converts paths delimited by backslashes into paths | |
delimited by periods, suitable for use as embedded resource names. | |
The end result of this is that all your XNB files for this project | |
will be added to your output assembly as Embedded Resources. | |
Additionally, the XNB files will not be copied to the output directory | |
(you can remove lines 9 and 10 if you *do* want that to happen). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Target Name="BeforeBuild" DependsOnTargets="BuildContent"> | |
<ItemGroup> | |
<!-- Include just-built XNB files as embedded resources in output assembly --> | |
<EmbeddedResource Include="@(ExtraContent)"> | |
<LogicalName>Apollo.Resources.Compiled.$([System.String]::new('%(RecursiveDir)').Replace('\', '.'))%(Filename)%(Extension)</LogicalName> | |
</EmbeddedResource> | |
<!-- Don't copy XNB files to output directory --> | |
<Content Remove="@(ExtraContent->'$(ParentOutputDir)\%(RecursiveDir)%(Filename)%(Extension)')" Condition="$(MonoGamePlatform) != 'Android'" /> | |
<AndroidAsset Remove="@(ExtraContent->'$(ParentOutputDir)\%(RecursiveDir)%(Filename)%(Extension)')" Condition="$(MonoGamePlatform) == 'Android'" /> | |
</ItemGroup> | |
</Target> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing @tgjones. How is it loaded with the contentmanager? Cheers, Georg