|
5 | 5 | using System.IO; |
6 | 6 | using System.Linq; |
7 | 7 | using Microsoft.Build.Evaluation; |
| 8 | +using Microsoft.Build.Shared; |
8 | 9 | using Shouldly; |
9 | 10 | using Xunit; |
10 | 11 |
|
@@ -68,6 +69,57 @@ public void DoesNotImportProjectIfNotExist() |
68 | 69 | project.GetPropertyValue(PropertyNameToSignalImportSucceeded).ShouldBeEmpty(); |
69 | 70 | } |
70 | 71 |
|
| 72 | + [Fact] |
| 73 | + public void DoesNotImportProjectIfRestoring() |
| 74 | + { |
| 75 | + ObjectModelHelpers.CreateFileInTempProjectDirectory(ImportProjectPath, BasicProjectImportContents); |
| 76 | + |
| 77 | + Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, $@" |
| 78 | + <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion`> |
| 79 | + <PropertyGroup> |
| 80 | + <{MSBuildConstants.MSBuildIsRestoring}>true</{MSBuildConstants.MSBuildIsRestoring}> |
| 81 | + </PropertyGroup> |
| 82 | +
|
| 83 | + <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> |
| 84 | +
|
| 85 | + <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> |
| 86 | + </Project> |
| 87 | + ")); |
| 88 | + |
| 89 | + string projectExtensionsPath = project.GetPropertyValue("MSBuildProjectExtensionsPath"); |
| 90 | + |
| 91 | + projectExtensionsPath.ShouldNotBeNullOrWhiteSpace(); |
| 92 | + Directory.Exists(projectExtensionsPath).ShouldBeTrue(); |
| 93 | + project.GetPropertyValue(PropertyNameToEnableImport).ShouldBe(bool.FalseString, StringCompareShould.IgnoreCase); |
| 94 | + project.GetPropertyValue(PropertyNameToSignalImportSucceeded).ShouldBeEmpty(); |
| 95 | + } |
| 96 | + |
| 97 | + [Fact] |
| 98 | + public void ImportsProjectIfRestoringAndExplicitlySet() |
| 99 | + { |
| 100 | + ObjectModelHelpers.CreateFileInTempProjectDirectory(ImportProjectPath, BasicProjectImportContents); |
| 101 | + |
| 102 | + Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory(ObjectModelHelpers.CreateFileInTempProjectDirectory(_projectRelativePath, $@" |
| 103 | + <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion`> |
| 104 | + <PropertyGroup> |
| 105 | + <{PropertyNameToEnableImport}>true</{PropertyNameToEnableImport}> |
| 106 | + <{MSBuildConstants.MSBuildIsRestoring}>true</{MSBuildConstants.MSBuildIsRestoring}> |
| 107 | + </PropertyGroup> |
| 108 | +
|
| 109 | + <Import Project=`$(MSBuildBinPath)\Microsoft.Common.props` /> |
| 110 | +
|
| 111 | + <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.targets` /> |
| 112 | + </Project> |
| 113 | + ")); |
| 114 | + |
| 115 | + string projectExtensionsPath = project.GetPropertyValue("MSBuildProjectExtensionsPath"); |
| 116 | + |
| 117 | + projectExtensionsPath.ShouldNotBeNullOrWhiteSpace(); |
| 118 | + Directory.Exists(projectExtensionsPath).ShouldBeTrue(); |
| 119 | + project.GetPropertyValue(PropertyNameToEnableImport).ShouldBe(bool.TrueString, StringCompareShould.IgnoreCase); |
| 120 | + project.GetPropertyValue(PropertyNameToSignalImportSucceeded).ShouldBe(bool.TrueString, StringCompareShould.IgnoreCase); |
| 121 | + } |
| 122 | + |
71 | 123 | /// <summary> |
72 | 124 | /// Ensures that even if the MSBuildProjectExtensionsPath exists, the extensions are not imported if the functionality is disabled via the <see cref="PropertyNameToEnableImport"/>. |
73 | 125 | /// </summary> |
|
0 commit comments