Skip to content

Commit b30b9f9

Browse files
authored
Use global properties from ProjectCreator.Create() in TryRestore() (#339)
1 parent 17b86a5 commit b30b9f9

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ NuGet and MSBuild are very tightly coupled and a lot of times you need packages
232232
2. Package feed - This allows you to create a file-based package feed of actual `.nupkg` files.
233233

234234
## Package Repository
235-
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]
235+
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)
236236

237237
### Examples
238238

@@ -302,7 +302,7 @@ using PackageRepository packageRepository = PackageRepository.Create(TestRootPat
302302
```
303303

304304
## Package Feed
305-
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].
305+
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).
306306

307307
### Example
308308

src/Microsoft.Build.Utilities.ProjectCreation.UnitTests/BuildTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,5 +390,27 @@ public void RestoreTargetCanBeRun()
390390

391391
buildOutput.MessageEvents.High.ShouldContain(i => i.Message == "312D2E6ABDDC4735B437A016CED1A68E" && i.Importance == MessageImportance.High, buildOutput.GetConsoleLog());
392392
}
393+
394+
[Fact]
395+
public void RestoreUsesGlobalPropertiesFromCreate()
396+
{
397+
Dictionary<string, string> globalProperties = new Dictionary<string, string>
398+
{
399+
["SomeGlobalProperty"] = "04BB4AFE8AE14B7A8E3511B5F2CD442B",
400+
};
401+
402+
ProjectCreator
403+
.Create(
404+
path: Path.Combine(TestRootPath, "project1.proj"),
405+
globalProperties: globalProperties)
406+
.Target("Restore")
407+
.TaskMessage("$(SomeGlobalProperty)", MessageImportance.High)
408+
.TaskError("SomeGlobalProperty was not defined", condition: "'$(SomeGlobalProperty)' == ''")
409+
.TryRestore(out bool result, out BuildOutput buildOutput);
410+
411+
result.ShouldBeTrue(buildOutput.GetConsoleLog());
412+
413+
buildOutput.MessageEvents.High.ShouldContain(i => i.Message == "04BB4AFE8AE14B7A8E3511B5F2CD442B" && i.Importance == MessageImportance.High, buildOutput.GetConsoleLog());
414+
}
393415
}
394416
}

src/Microsoft.Build.Utilities.ProjectCreation/ProjectCreator.Build.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ private void Restore(IDictionary<string, string>? globalProperties, BuildOutput
549549
#else
550550
Dictionary<string, string?> restoreGlobalProperties =
551551
#endif
552-
new(globalProperties ?? ProjectCollection.GlobalProperties);
552+
new(globalProperties ?? _globalProperties ?? ProjectCollection.GlobalProperties);
553553

554554
restoreGlobalProperties["ExcludeRestorePackageImports"] = "true";
555555
restoreGlobalProperties["MSBuildRestoreSessionId"] = Guid.NewGuid().ToString("D");

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "14.0",
2+
"version": "14.1",
33
"assemblyVersion": "1.0",
44
"buildNumberOffset": -2,
55
"nugetPackageVersion": {

0 commit comments

Comments
 (0)