From f113a922239d4ef9fcda3617bb84152743e2cace Mon Sep 17 00:00:00 2001 From: Jeff Kluge Date: Thu, 11 Sep 2025 09:15:35 -0700 Subject: [PATCH 1/2] Use global properties from ProjectCreator.Create() in TryRestore() --- .../BuildTests.cs | 22 +++++++++++++++++++ .../ProjectCreator.Build.cs | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs index 28ec6c9..f3b8f48 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs @@ -390,5 +390,27 @@ public void RestoreTargetCanBeRun() buildOutput.MessageEvents.High.ShouldContain(i => i.Message == "312D2E6ABDDC4735B437A016CED1A68E" && i.Importance == MessageImportance.High, buildOutput.GetConsoleLog()); } + + [Fact] + public void RestoreUsesGlobalPropertiesFromCreate() + { + Dictionary globalProperties = new Dictionary + { + ["SomeGlobalProperty"] = "04BB4AFE8AE14B7A8E3511B5F2CD442B", + }; + + ProjectCreator + .Create( + path: Path.Combine(TestRootPath, "project1.proj"), + globalProperties: globalProperties) + .Target("Restore") + .TaskMessage("$(SomeGlobalProperty)", MessageImportance.High) + .TaskError("SomeGlobalProperty was not defined", condition: "'$(SomeGlobalProperty)' == ''") + .TryRestore(out bool result, out BuildOutput buildOutput); + + result.ShouldBeTrue(buildOutput.GetConsoleLog()); + + buildOutput.MessageEvents.High.ShouldContain(i => i.Message == "04BB4AFE8AE14B7A8E3511B5F2CD442B" && i.Importance == MessageImportance.High, buildOutput.GetConsoleLog()); + } } } \ No newline at end of file diff --git a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Build.cs b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Build.cs index 2e8bee8..87ca947 100644 --- a/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Build.cs +++ b/src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Build.cs @@ -549,7 +549,7 @@ private void Restore(IDictionary? globalProperties, BuildOutput #else Dictionary restoreGlobalProperties = #endif - new(globalProperties ?? ProjectCollection.GlobalProperties); + new(globalProperties ?? _globalProperties ?? ProjectCollection.GlobalProperties); restoreGlobalProperties["ExcludeRestorePackageImports"] = "true"; restoreGlobalProperties["MSBuildRestoreSessionId"] = Guid.NewGuid().ToString("D"); From 232a25c0a4cd4801642d5e49ac8ac4c164da3693 Mon Sep 17 00:00:00 2001 From: Jeff Kluge Date: Thu, 11 Sep 2025 09:25:33 -0700 Subject: [PATCH 2/2] Update version and fix bad links in doc --- README.md | 4 ++-- version.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c326684..5beadd1 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ NuGet and MSBuild are very tightly coupled and a lot of times you need packages 2. Package feed - This allows you to create a file-based package feed of actual `.nupkg` files. ## Package Repository -Create a package repository if you want to generate packages as if they've already been installed. If you want to create actual `.nupkg` packages, see [Package Feed] +Create a package repository if you want to generate packages as if they've already been installed. If you want to create actual `.nupkg` packages, see [Package Feed](#Package-Feed) ### Examples @@ -302,7 +302,7 @@ using PackageRepository packageRepository = PackageRepository.Create(TestRootPat ``` ## Package Feed -Create a package feed if you want to generate `.nupkg` packages that can be installed by NuGet. If you want to create a repository of packages as if they've already been installed, see [Package Repository]. +Create a package feed if you want to generate `.nupkg` packages that can be installed by NuGet. If you want to create a repository of packages as if they've already been installed, see [Package Repository](#Package-Repository). ### Example diff --git a/version.json b/version.json index 45b0c4e..4f55fd0 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "14.0", + "version": "14.1", "assemblyVersion": "1.0", "buildNumberOffset": -2, "nugetPackageVersion": {