mirror of
https://github.com/Ellpeck/Contentless.git
synced 2024-11-27 17:28:35 +01:00
Compare commits
No commits in common. "bbb4b539cc40ab441b8bcfb6af6f8c75c7d15571" and "d672f7e4b26ec17facb8b0a15ec6a6d382c7d0ec" have entirely different histories.
bbb4b539cc
...
d672f7e4b2
12 changed files with 74 additions and 209 deletions
|
@ -1,11 +1,9 @@
|
|||
steps:
|
||||
build:
|
||||
image: mcr.microsoft.com/dotnet/sdk:8.0-jammy
|
||||
image: mcr.microsoft.com/dotnet/sdk:6.0
|
||||
commands:
|
||||
- dotnet build Contentless
|
||||
test:
|
||||
image: mcr.microsoft.com/dotnet/sdk:8.0-jammy
|
||||
image: mcr.microsoft.com/dotnet/sdk:6.0
|
||||
commands:
|
||||
- dotnet restore Test
|
||||
- dotnet run --project Contentless Test/Content/Content.mgcb Test/Test.csproj
|
||||
- dotnet build Test
|
||||
- dotnet run --project Contentless Test/Content/Content.mgcb
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
|
@ -15,8 +14,6 @@ public class Config {
|
|||
[JsonProperty("overrides")]
|
||||
public Dictionary<string, Override> Overrides = new();
|
||||
|
||||
[JsonProperty("references")]
|
||||
public string[] References = Array.Empty<string>();
|
||||
}
|
||||
|
||||
public class Override {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RollForward>Major</RollForward>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -11,21 +11,15 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MonoGame.Framework.Content.Pipeline" Version="3.8.1.303">
|
||||
<PackageReference Include="MonoGame.Framework.Content.Pipeline" Version="3.8.0.1641">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.1.303">
|
||||
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Build" Version="17.3.2">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NuGet.Configuration" Version="6.8.0">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -10,15 +10,15 @@
|
|||
<repository type="git" url="https://github.com/Ellpeck/Contentless" />
|
||||
<readme>README.md</readme>
|
||||
<icon>Logo.png</icon>
|
||||
<version>3.1.2</version>
|
||||
<version>3.0.7</version>
|
||||
<dependencies>
|
||||
<group targetFramework="net8.0" />
|
||||
<group targetFramework="net6.0" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="_._" target="lib/net8.0/" />
|
||||
<file src="_._" target="lib/net6.0/" />
|
||||
<file src="Contentless.targets" target="build/Contentless.targets" />
|
||||
<file src="bin\Debug\net8.0\**\*" target="tools/" />
|
||||
<file src="bin\Debug\net6.0\**\*" target="tools/" />
|
||||
<file src="../README.md" target="" />
|
||||
<file src="../Logo.png" target="" />
|
||||
</files>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<Project>
|
||||
<Target Name="Contentless" BeforeTargets="BeforeBuild">
|
||||
<Exec Command="dotnet $(MSBuildThisFileDirectory)/../tools/Contentless.dll @(MonoGameContentReference) $(MSBuildProjectFullPath)" />
|
||||
<Exec Command="dotnet $(MSBuildThisFileDirectory)/../tools/Contentless.dll @(MonoGameContentReference)" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -4,25 +4,23 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Build.Construction;
|
||||
using Microsoft.Xna.Framework.Content.Pipeline;
|
||||
using Newtonsoft.Json;
|
||||
using NuGet.Configuration;
|
||||
|
||||
namespace Contentless;
|
||||
|
||||
public static class Program {
|
||||
|
||||
public static int Main(string[] args) {
|
||||
if (args.Length < 1) {
|
||||
Console.Error.WriteLine("Please specify the location of the content file you want to use");
|
||||
return 1;
|
||||
public static void Main(string[] args) {
|
||||
if (args.Length != 1) {
|
||||
Console.WriteLine("Please specify the location of the content file you want to use");
|
||||
return;
|
||||
}
|
||||
|
||||
var contentFile = new FileInfo(Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, args[0])));
|
||||
if (!contentFile.Exists || contentFile.Extension != ".mgcb") {
|
||||
Console.Error.WriteLine($"Unable to find valid content file at {contentFile}");
|
||||
return 1;
|
||||
if (!contentFile.Exists) {
|
||||
Console.WriteLine($"Unable to find content file {contentFile}");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine($"Using content file {contentFile}");
|
||||
|
@ -37,8 +35,7 @@ public static class Program {
|
|||
config = JsonConvert.DeserializeObject<Config>(stream.ReadToEnd());
|
||||
Console.WriteLine($"Using config from {configFile}");
|
||||
} catch (Exception e) {
|
||||
Console.Error.WriteLine($"Error loading config from {configFile}: {e}");
|
||||
return 1;
|
||||
Console.WriteLine($"Error loading config from {configFile}: {e}");
|
||||
}
|
||||
} else {
|
||||
Console.WriteLine("Using default config");
|
||||
|
@ -46,76 +43,17 @@ public static class Program {
|
|||
var excluded = config.ExcludedFiles.Select(Program.MakeFileRegex).ToArray();
|
||||
var overrides = Program.GetOverrides(config.Overrides).ToArray();
|
||||
|
||||
string packagesFolder = null;
|
||||
var referencesVersions = config.References.ToDictionary(x => x, _ => (string) null, StringComparer.OrdinalIgnoreCase);
|
||||
if (config.References.Length > 0) {
|
||||
if (args.Length > 1) {
|
||||
var csprojFullPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, args[1]));
|
||||
if (!File.Exists(csprojFullPath) || Path.GetExtension(csprojFullPath) != ".csproj") {
|
||||
Console.Error.WriteLine($"Unable to find valid project file at {contentFile}");
|
||||
return 1;
|
||||
}
|
||||
Program.ExtractVersions(csprojFullPath, referencesVersions);
|
||||
var settings = Settings.LoadDefaultSettings(Path.GetDirectoryName(csprojFullPath));
|
||||
packagesFolder = SettingsUtility.GetGlobalPackagesFolder(settings);
|
||||
} else {
|
||||
Console.Error.WriteLine("The config file contains references, but no project file was specified. Please specify the location of the content file you want to use for gathering references as the second argument.");
|
||||
}
|
||||
}
|
||||
|
||||
const string referenceHeader = "/reference:";
|
||||
var changed = false;
|
||||
var referencesSyncs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
// load any references to be able to include custom content types as well
|
||||
for (var i = 0; i < content.Count; i++) {
|
||||
var line = content[i];
|
||||
if (!line.StartsWith(referenceHeader))
|
||||
foreach (var line in content) {
|
||||
if (!line.StartsWith("/reference:"))
|
||||
continue;
|
||||
var reference = line[referenceHeader.Length..];
|
||||
var libraryName = Path.GetFileName(reference)[..^4];
|
||||
|
||||
if (referencesVersions.TryGetValue(libraryName, out var version) && version is not null) {
|
||||
var fullLibraryPath = Program.CalculateFullPathToLibrary(packagesFolder, libraryName, version);
|
||||
if (reference != fullLibraryPath) {
|
||||
Console.WriteLine($"Changing reference from {reference} to {fullLibraryPath}");
|
||||
reference = fullLibraryPath;
|
||||
content[i] = referenceHeader + fullLibraryPath;
|
||||
changed = true;
|
||||
} else {
|
||||
if (config.LogSkipped)
|
||||
Console.WriteLine($"Skipping reference replacement for {fullLibraryPath} which already matched");
|
||||
}
|
||||
referencesSyncs.Add(libraryName);
|
||||
}
|
||||
|
||||
var reference = line.Substring(11);
|
||||
var refPath = Path.GetFullPath(Path.Combine(contentFile.DirectoryName, reference));
|
||||
Program.SafeAssemblyLoad(refPath);
|
||||
Console.WriteLine($"Using reference {refPath}");
|
||||
}
|
||||
|
||||
// check references not in .mgcb now
|
||||
var referencesLastIndex = 0;
|
||||
// find place where I can add new reference
|
||||
for (var i = 0; i < content.Count; i++) {
|
||||
var line = content[i];
|
||||
if (line.StartsWith(referenceHeader)) {
|
||||
referencesLastIndex = i + 1;
|
||||
} else if (line.StartsWith("/importer:") || line.StartsWith("/processor:") || line.StartsWith("/build:") || line.Contains("-- Content --")) {
|
||||
if (referencesLastIndex == 0)
|
||||
referencesLastIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (var reference in referencesVersions)
|
||||
if (!referencesSyncs.Contains(reference.Key) && reference.Value is not null) {
|
||||
try {
|
||||
var path = Program.CalculateFullPathToLibrary(packagesFolder, reference.Key, reference.Value);
|
||||
content.Insert(referencesLastIndex++, referenceHeader + path);
|
||||
changed = true;
|
||||
Program.SafeAssemblyLoad(path);
|
||||
Console.WriteLine($"Adding reference {path}");
|
||||
Assembly.LoadFrom(refPath);
|
||||
Console.WriteLine($"Using reference {refPath}");
|
||||
} catch (Exception e) {
|
||||
Console.Error.WriteLine($"Error adding reference {reference.Key} {e}");
|
||||
Console.WriteLine($"Error loading reference {refPath}: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,11 +62,12 @@ public static class Program {
|
|||
Console.WriteLine($"Found possible importer types {string.Join(", ", importers)}");
|
||||
Console.WriteLine($"Found possible processor types {string.Join(", ", processors)}");
|
||||
|
||||
var changed = false;
|
||||
foreach (var file in contentFile.Directory.EnumerateFiles("*", SearchOption.AllDirectories)) {
|
||||
// is the file the content or config file?
|
||||
if (file.Name == contentFile.Name || file.Name == configFile.Name)
|
||||
continue;
|
||||
var relative = Path.GetRelativePath(contentFile.DirectoryName, file.FullName).Replace('\\', '/');
|
||||
var relative = Program.GetRelativePath(contentFile.DirectoryName, file.FullName).Replace("\\", "/");
|
||||
|
||||
// is the file in an excluded directory?
|
||||
if (excluded.Any(e => e.IsMatch(relative))) {
|
||||
|
@ -163,7 +102,7 @@ public static class Program {
|
|||
if (!string.IsNullOrEmpty(over.Override.Importer)) {
|
||||
importer = importers.Find(i => i.Type.Name == over.Override.Importer);
|
||||
if (importer == null) {
|
||||
Console.Error.WriteLine($"Override importer {over.Override.Importer} not found for file {relative}");
|
||||
Console.WriteLine($"Override importer {over.Override.Importer} not found for file {relative}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -171,7 +110,7 @@ public static class Program {
|
|||
if (!string.IsNullOrEmpty(over.Override.Processor)) {
|
||||
processor = processors.Find(p => p == over.Override.Processor);
|
||||
if (processor == null) {
|
||||
Console.Error.WriteLine($"Override processor {over.Override.Processor} not found for file {relative}");
|
||||
Console.WriteLine($"Override processor {over.Override.Processor} not found for file {relative}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +123,7 @@ public static class Program {
|
|||
|
||||
// no importer found :(
|
||||
if (importer == null || processor == null) {
|
||||
Console.Error.WriteLine($"No importer or processor found for file {relative}");
|
||||
Console.WriteLine($"No importer or processor found for file {relative}");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -201,38 +140,6 @@ public static class Program {
|
|||
Console.WriteLine("Wrote changes to content file");
|
||||
}
|
||||
Console.Write("Done");
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static void SafeAssemblyLoad(string refPath) {
|
||||
try {
|
||||
Assembly.LoadFrom(refPath);
|
||||
} catch (Exception e) {
|
||||
Console.Error.WriteLine($"Error loading reference {refPath} {e}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExtractVersions(string csprojPath, Dictionary<string, string> referencesVersions) {
|
||||
Console.WriteLine($"Using project file {csprojPath}");
|
||||
var projectRootElement = ProjectRootElement.Open(csprojPath);
|
||||
foreach (var property in projectRootElement.AllChildren.Where(x => x.ElementName == "PackageReference").Select(x => x as ProjectItemElement)) {
|
||||
var libraryName = property.Include;
|
||||
if (property.Children.FirstOrDefault(x => x.ElementName == "Version") is not ProjectMetadataElement versionElement)
|
||||
continue;
|
||||
var version = versionElement.Value;
|
||||
if (referencesVersions.ContainsKey(libraryName)) {
|
||||
referencesVersions[libraryName] = version;
|
||||
Console.WriteLine($"Found reference {libraryName} {version} in project file");
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var library in referencesVersions)
|
||||
if (library.Value is null)
|
||||
Console.Error.WriteLine($"Unable to find reference {library.Key} in project file");
|
||||
}
|
||||
|
||||
private static string CalculateFullPathToLibrary(string packageFolder, string libraryName, string referencesVersion) {
|
||||
return Path.Combine(packageFolder, libraryName.ToLowerInvariant(), referencesVersion, "tools", libraryName + ".dll").Replace('\\', '/');
|
||||
}
|
||||
|
||||
private static (List<ImporterInfo>, List<string>) GetContentData() {
|
||||
|
@ -249,7 +156,7 @@ public static class Program {
|
|||
processors.Add(type.Name);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Console.Error.WriteLine($"Error gathering types in reference {assembly}: {e}");
|
||||
Console.WriteLine($"Error gathering types in reference {assembly}: {e}");
|
||||
}
|
||||
}
|
||||
return (importers, processors);
|
||||
|
@ -313,6 +220,12 @@ public static class Program {
|
|||
Console.WriteLine($"Adding file {relative} with the Copy build action");
|
||||
}
|
||||
|
||||
private static string GetRelativePath(string relativeTo, string path) {
|
||||
if (!relativeTo.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
relativeTo += Path.DirectorySeparatorChar;
|
||||
return path.Replace(relativeTo, "");
|
||||
}
|
||||
|
||||
private static Regex MakeFileRegex(string s) {
|
||||
return new Regex(s.Replace(".", "[.]").Replace("*", ".*").Replace("?", "."));
|
||||
}
|
||||
|
|
|
@ -59,10 +59,7 @@ If you want to change the way Contentless works, you can use a configuration fil
|
|||
"TextureFormat": "Compressed"
|
||||
}
|
||||
}
|
||||
},
|
||||
// A set of content pipeline library references that should optionally be added to the content file, or whose paths should be changed in the content file if they don't match the project's package references
|
||||
// Default: []
|
||||
"references": ["MonoGame.Extended.Content.Pipeline"]
|
||||
}
|
||||
}
|
||||
```
|
||||
For an example of a config in use, see the [test config](https://github.com/Ellpeck/Contentless/blob/main/Test/Content/Contentless.json).
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
{
|
||||
"version": 1,
|
||||
"isRoot": true,
|
||||
"tools": {
|
||||
"dotnet-mgcb": {
|
||||
"version": "3.8.1.303",
|
||||
"commands": [
|
||||
"mgcb"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor": {
|
||||
"version": "3.8.1.303",
|
||||
"commands": [
|
||||
"mgcb-editor"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-linux": {
|
||||
"version": "3.8.1.303",
|
||||
"commands": [
|
||||
"mgcb-editor-linux"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-windows": {
|
||||
"version": "3.8.1.303",
|
||||
"commands": [
|
||||
"mgcb-editor-windows"
|
||||
]
|
||||
},
|
||||
"dotnet-mgcb-editor-mac": {
|
||||
"version": "3.8.1.303",
|
||||
"commands": [
|
||||
"mgcb-editor-mac"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,31 +10,32 @@
|
|||
|
||||
#-------------------------------- References --------------------------------#
|
||||
|
||||
/reference:C:/Users/me/.nuget/packages/monogame.extended.content.pipeline/3.9.0-alpha0093/tools/MonoGame.Extended.Content.Pipeline.dll
|
||||
/reference:..\..\..\.nuget\packages\monogame.extended.content.pipeline\3.8.0\tools\MonoGame.Extended.Content.Pipeline.dll
|
||||
|
||||
#---------------------------------- Content ---------------------------------#
|
||||
|
||||
#begin Json/Copy.json
|
||||
/copy:Json/Copy.json
|
||||
|
||||
#begin Json/Test.json
|
||||
/copy:Json/Test.json
|
||||
/importer:JsonContentImporter
|
||||
/processor:FontTextureProcessor
|
||||
/build:Json/Test.json
|
||||
|
||||
#begin Locale/Interface.xml
|
||||
/importer:XmlImporter
|
||||
/processor:PassThroughProcessor
|
||||
/processor:FontTextureProcessor
|
||||
/build:Locale/Interface.xml
|
||||
|
||||
#begin Textures/Icons.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:TextureFormat=NoChange
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Textures/Icons.png
|
||||
|
||||
#begin Textures/Inside.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:TextureFormat=NoChange
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Textures/Inside.png
|
||||
|
||||
#begin Tiled/Map.tmx
|
||||
|
@ -42,7 +43,14 @@
|
|||
/processor:TiledMapProcessor
|
||||
/build:Tiled/Map.tmx
|
||||
|
||||
#begin Tiled/Tiles.png
|
||||
/importer:TextureImporter
|
||||
/processor:TextureProcessor
|
||||
/processorParam:TextureFormat=Compressed
|
||||
/build:Tiled/Tiles.png
|
||||
|
||||
#begin Tiled/Tileset.tsx
|
||||
/importer:TiledMapTilesetImporter
|
||||
/processor:TiledMapTilesetProcessor
|
||||
/build:Tiled/Tileset.tsx
|
||||
|
||||
|
|
|
@ -2,25 +2,27 @@
|
|||
"exclude": [
|
||||
"obj/",
|
||||
"bin/",
|
||||
"Ex*.png",
|
||||
"Tiled/*.png"
|
||||
"Ex*.png"
|
||||
],
|
||||
"logSkipped": true,
|
||||
"references": ["MonoGame.Extended.Content.Pipeline"],
|
||||
"overrides": {
|
||||
"Copy.*": {
|
||||
"copy": true
|
||||
},
|
||||
".json": {
|
||||
"copy": true
|
||||
"importer": "JsonContentImporter",
|
||||
"processor": "FontTextureProcessor"
|
||||
},
|
||||
".ogg": {
|
||||
"importer": "OggImporter",
|
||||
"processor": "SongProcessor"
|
||||
},
|
||||
".xml": {
|
||||
"processor": "FontTextureProcessor"
|
||||
},
|
||||
".png": {
|
||||
"processorParams": {
|
||||
"TextureFormat": "NoChange"
|
||||
"TextureFormat": "Compressed"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
<add key="lithiumtoast" value="https://www.myget.org/F/lithiumtoast/api/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
|
@ -1,16 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<MonoGamePlatform>DesktopGL</MonoGamePlatform>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MonoGame.Extended.Content.Pipeline" Version="3.9.0-alpha0093" />
|
||||
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.1.303" />
|
||||
<PackageReference Include="MonoGame.Extended.Content.Pipeline" Version="3.8.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Content\Content.mgcb" />
|
||||
<MonoGameContentReference Include="Content\Content.mgcb" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
Loading…
Reference in a new issue