From d78e0a842638df9c98a8f7637b125d36e488a367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacio=20Rold=C3=A1n=20Etcheverry?= Date: Sun, 27 Feb 2022 21:57:53 +0100 Subject: [PATCH] C#: Make GodotSharp API a NuGet package In the past, the Godot editor distributed the API assemblies and copied them to project directories for projects to reference them. This changed with the move to .NET 5/6. Godot no longer copies the assemblies to project directories. However, the project Sdk still tried to reference them from the same location. From now on, the GodotSharp API is distributed as a NuGet package, which the Sdk can reference. Added an option to `build_assemblies.py` to copy all Godot NuGet packages to an existing local NuGet source. This will be needed during development, while packages are not published to a remote NuGet repository. This option also makes sure to remove packages of the same version installed (~/.nuget/packages). Very useful during development, when packages change, to make sure the package being used by a project is the same we just built and not one from a previous build. A local NuGet source can be created like this: ``` mkdir ~/MyLocalNuGetSource && \ dotnet nuget add source ~/MyLocalNuGetSource/ -n MyLocalNuGetSource ``` --- modules/mono/Directory.Build.props | 5 +++- modules/mono/Directory.Build.targets | 22 ++++++++++++++ modules/mono/SdkPackageVersions.props | 3 +- .../mono/build_scripts/build_assemblies.py | 29 +++++++++++++++---- .../Godot.NET.Sdk/Godot.NET.Sdk.csproj | 10 +------ .../Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props | 15 ---------- .../Godot.NET.Sdk/Sdk/Sdk.targets | 6 ++++ .../Godot.SourceGenerators.csproj | 8 ----- .../GodotSharp/GodotSharp/GodotSharp.csproj | 19 ++++++++++++ .../GodotSharpEditor/GodotSharpEditor.csproj | 13 +++++++++ 10 files changed, 90 insertions(+), 40 deletions(-) create mode 100644 modules/mono/Directory.Build.targets diff --git a/modules/mono/Directory.Build.props b/modules/mono/Directory.Build.props index fbf864b11b0..f7c8a825f9d 100644 --- a/modules/mono/Directory.Build.props +++ b/modules/mono/Directory.Build.props @@ -1,3 +1,6 @@ - + + $(MSBuildThisFileDirectory)\SdkPackageVersions.props + + diff --git a/modules/mono/Directory.Build.targets b/modules/mono/Directory.Build.targets new file mode 100644 index 00000000000..98410b93aed --- /dev/null +++ b/modules/mono/Directory.Build.targets @@ -0,0 +1,22 @@ + + + <_HasNuGetPackage Condition=" '$(_HasNuGetPackage)' == '' And '$(PackageId)' != '' And '$(GeneratePackageOnBuild.ToLower())' == 'true' ">true + <_HasNuGetPackage Condition=" '$(_HasNuGetPackage)' == '' ">false + + + + $(MSBuildThisFileDirectory)\..\..\ + $(GodotSourceRootPath)\bin\GodotSharp\ + + + + + + + + + + diff --git a/modules/mono/SdkPackageVersions.props b/modules/mono/SdkPackageVersions.props index 50ef6d8d6c0..65094aa34f5 100644 --- a/modules/mono/SdkPackageVersions.props +++ b/modules/mono/SdkPackageVersions.props @@ -1,7 +1,8 @@ 4.0.*-* - 4.0.0-dev7 + 4.0.0-dev + 4.0.0-dev8 4.0.0-dev8 diff --git a/modules/mono/build_scripts/build_assemblies.py b/modules/mono/build_scripts/build_assemblies.py index 9cf93302321..fa3be684bdc 100755 --- a/modules/mono/build_scripts/build_assemblies.py +++ b/modules/mono/build_scripts/build_assemblies.py @@ -195,7 +195,7 @@ def run_msbuild(tools: ToolsLocation, sln: str, msbuild_args: [str] = None): return subprocess.call(args, env=msbuild_env) -def build_godot_api(msbuild_tool, module_dir, output_dir): +def build_godot_api(msbuild_tool, module_dir, output_dir, push_nupkgs_local): target_filenames = [ "GodotSharp.dll", "GodotSharp.pdb", @@ -213,11 +213,15 @@ def build_godot_api(msbuild_tool, module_dir, output_dir): targets = [os.path.join(editor_api_dir, filename) for filename in target_filenames] + args = ["/restore", "/t:Build", "/p:Configuration=" + build_config, "/p:NoWarn=1591"] + if push_nupkgs_local: + args += ["/p:ClearNuGetLocalCache=true", "/p:PushNuGetToLocalSource=" + push_nupkgs_local] + sln = os.path.join(module_dir, "glue/GodotSharp/GodotSharp.sln") exit_code = run_msbuild( msbuild_tool, sln=sln, - msbuild_args=["/restore", "/t:Build", "/p:Configuration=" + build_config, "/p:NoWarn=1591"], + msbuild_args=args, ) if exit_code != 0: return exit_code @@ -252,9 +256,9 @@ def build_godot_api(msbuild_tool, module_dir, output_dir): return 0 -def build_all(msbuild_tool, module_dir, output_dir, dev_debug, godot_platform): +def build_all(msbuild_tool, module_dir, output_dir, godot_platform, dev_debug, push_nupkgs_local): # Godot API - exit_code = build_godot_api(msbuild_tool, module_dir, output_dir) + exit_code = build_godot_api(msbuild_tool, module_dir, output_dir, push_nupkgs_local) if exit_code != 0: return exit_code @@ -263,13 +267,18 @@ def build_all(msbuild_tool, module_dir, output_dir, dev_debug, godot_platform): args = ["/restore", "/t:Build", "/p:Configuration=" + ("Debug" if dev_debug else "Release")] + ( ["/p:GodotPlatform=" + godot_platform] if godot_platform else [] ) + if push_nupkgs_local: + args += ["/p:ClearNuGetLocalCache=true", "/p:PushNuGetToLocalSource=" + push_nupkgs_local] exit_code = run_msbuild(msbuild_tool, sln=sln, msbuild_args=args) if exit_code != 0: return exit_code # Godot.NET.Sdk + args = ["/restore", "/t:Build", "/p:Configuration=Release"] + if push_nupkgs_local: + args += ["/p:ClearNuGetLocalCache=true", "/p:PushNuGetToLocalSource=" + push_nupkgs_local] sln = os.path.join(module_dir, "editor/Godot.NET.Sdk/Godot.NET.Sdk.sln") - exit_code = run_msbuild(msbuild_tool, sln=sln, msbuild_args=["/restore", "/t:Build", "/p:Configuration=Release"]) + exit_code = run_msbuild(msbuild_tool, sln=sln, msbuild_args=args) if exit_code != 0: return exit_code @@ -290,6 +299,7 @@ def main(): ) parser.add_argument("--godot-platform", type=str, default="") parser.add_argument("--mono-prefix", type=str, default="") + parser.add_argument("--push-nupkgs-local", type=str, default="") args = parser.parse_args() @@ -304,7 +314,14 @@ def main(): print("Unable to find MSBuild") sys.exit(1) - exit_code = build_all(msbuild_tool, module_dir, output_dir, args.godot_platform, args.dev_debug) + exit_code = build_all( + msbuild_tool, + module_dir, + output_dir, + args.godot_platform, + args.dev_debug, + args.push_nupkgs_local, + ) sys.exit(exit_code) diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Godot.NET.Sdk.csproj b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Godot.NET.Sdk.csproj index 4e9e7184daf..013b210ff43 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Godot.NET.Sdk.csproj +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Godot.NET.Sdk.csproj @@ -26,16 +26,8 @@ - + Sdk\SdkPackageVersions.props - - - - $(SolutionDir)\..\..\..\..\ - $(GodotSourceRootPath)\bin\GodotSharp\ - - - diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props index 9bc134818ae..652b9e8e434 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.props @@ -95,19 +95,4 @@ $(GodotDefineConstants);$(DefineConstants) - - - - - - $(GodotProjectDir).godot\mono\assemblies\$(GodotApiConfiguration)\GodotSharp.dll - - - $(GodotProjectDir).godot\mono\assemblies\$(GodotApiConfiguration)\GodotSharpEditor.dll - - diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets index 397ede9644e..aad4ea4553a 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.NET.Sdk/Sdk/Sdk.targets @@ -19,4 +19,10 @@ + + + + + + diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Godot.SourceGenerators.csproj b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Godot.SourceGenerators.csproj index d61d9f7f142..f51b5970c36 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Godot.SourceGenerators.csproj +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Godot.SourceGenerators.csproj @@ -30,12 +30,4 @@ - - - - $(SolutionDir)\..\..\..\..\ - $(GodotSourceRootPath)\bin\GodotSharp\ - - - diff --git a/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj b/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj index ce1a53cff2d..2e121bb7894 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj +++ b/modules/mono/glue/GodotSharp/GodotSharp/GodotSharp.csproj @@ -15,6 +15,25 @@ CS1591 + + Godot C# Core API. + Godot Engine contributors + + GodotSharp + 4.0.0 + $(PackageVersion_GodotSharp) + https://github.com/godotengine/godot/tree/master/modules/mono/glue/GodotSharp/GodotSharp + $(RepositoryUrl) + MIT + + true + + + + + SdkPackageVersions.props + + $(DefineConstants);GODOT diff --git a/modules/mono/glue/GodotSharp/GodotSharpEditor/GodotSharpEditor.csproj b/modules/mono/glue/GodotSharp/GodotSharpEditor/GodotSharpEditor.csproj index aebf3a4a182..ebf09aab7b0 100644 --- a/modules/mono/glue/GodotSharp/GodotSharpEditor/GodotSharpEditor.csproj +++ b/modules/mono/glue/GodotSharp/GodotSharpEditor/GodotSharpEditor.csproj @@ -10,6 +10,19 @@ true 10 + + Godot C# Editor API. + Godot Engine contributors + + GodotSharpEditor + 4.0.0 + $(PackageVersion_GodotSharp) + https://github.com/godotengine/godot/tree/master/modules/mono/glue/GodotSharp/GodotSharpEditor + $(RepositoryUrl) + MIT + + true + $(DefineConstants);GODOT