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: 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/build_scripts/build_assemblies.py | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'modules/mono/build_scripts') diff --git a/modules/mono/build_scripts/build_assemblies.py b/modules/mono/build_scripts/build_assemblies.py index 9cf9330232..fa3be684bd 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) -- cgit v1.2.3