1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

[3.2] C#: Support for building with the dotnet CLI

By adding a reference to the 'Microsoft.NETFramework.ReferenceAssemblies' nuget
package, we can build projects targeting .NET Framework with the dotnet CLI.
By referencing this package we also don't need to install Mono on Linux/macOS
or .NET Framework on Windows, as the assemblies are taken from the package.
This commit is contained in:
Ignacio Etcheverry
2020-05-10 22:56:35 +02:00
parent a9bcd8ba26
commit 3928fe200f
22 changed files with 232 additions and 436 deletions

View File

@@ -176,7 +176,7 @@ namespace GodotTools.ProjectEditor
void AddPropertyIfNotPresent(string name, string condition, string value)
{
if (root.PropertyGroups
.Any(g => (g.Condition == string.Empty || g.Condition.Trim() == condition) &&
.Any(g => (string.IsNullOrEmpty(g.Condition) || g.Condition.Trim() == condition) &&
g.Properties
.Any(p => p.Name == name &&
p.Value == value &&
@@ -267,7 +267,7 @@ namespace GodotTools.ProjectEditor
bool hasGodotProjectGeneratorVersion = false;
bool foundOldConfiguration = false;
foreach (var propertyGroup in root.PropertyGroups.Where(g => g.Condition == string.Empty))
foreach (var propertyGroup in root.PropertyGroups.Where(g => string.IsNullOrEmpty(g.Condition)))
{
if (!hasGodotProjectGeneratorVersion && propertyGroup.Properties.Any(p => p.Name == "GodotProjectGeneratorVersion"))
hasGodotProjectGeneratorVersion = true;
@@ -283,7 +283,7 @@ namespace GodotTools.ProjectEditor
if (!hasGodotProjectGeneratorVersion)
{
root.PropertyGroups.First(g => g.Condition == string.Empty)?
root.PropertyGroups.First(g => string.IsNullOrEmpty(g.Condition))?
.AddProperty("GodotProjectGeneratorVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString());
project.HasUnsavedChanges = true;
}
@@ -351,5 +351,25 @@ namespace GodotTools.ProjectEditor
MigrateConfigurationConditions("Tools", "Debug"); // Must be last
}
}
public static void EnsureHasNugetNetFrameworkRefAssemblies(MSBuildProject project)
{
var root = project.Root;
bool found = root.ItemGroups.Any(g => string.IsNullOrEmpty(g.Condition) && g.Items.Any(
item => item.ItemType == "PackageReference" && item.Include == "Microsoft.NETFramework.ReferenceAssemblies"));
if (found)
return;
var frameworkRefAssembliesItem = root.AddItem("PackageReference", "Microsoft.NETFramework.ReferenceAssemblies");
// Use metadata (child nodes) instead of attributes for the PackageReference.
// This is for compatibility with 3.2, where GodotTools uses an old Microsoft.Build.
frameworkRefAssembliesItem.AddMetadata("Version", "1.0.0");
frameworkRefAssembliesItem.AddMetadata("PrivateAssets", "All");
project.HasUnsavedChanges = true;
}
}
}