|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
| 4 | +using Microsoft.NET.Build.Tasks; |
| 5 | + |
4 | 6 | namespace Microsoft.NET.Build.Tests
|
5 | 7 | {
|
6 | 8 | public class GivenThatWeWantToBuildWithATargetPlatform : SdkTest
|
@@ -90,5 +92,82 @@ public void It_fails_on_unsupported_os()
|
90 | 92 | .And
|
91 | 93 | .HaveStdOutContaining("NETSDK1139");
|
92 | 94 | }
|
| 95 | + |
| 96 | + [Fact] |
| 97 | + public void It_fails_if_targetplatformversion_is_constant_only() |
| 98 | + { |
| 99 | + var testProject = new TestProject() |
| 100 | + { |
| 101 | + Name = "It_fails_if_targetplatformversion_is_constant_only", |
| 102 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 103 | + }; |
| 104 | + var testAsset = _testAssetsManager.CreateTestProject(testProject); |
| 105 | + |
| 106 | + |
| 107 | + string DirectoryBuildTargetsContent = $@" |
| 108 | +<Project> |
| 109 | + <ItemGroup> |
| 110 | + <SdkSupportedTargetPlatformVersion Include=""111.0"" DefineConstantsOnly=""true"" /> |
| 111 | + <SdkSupportedTargetPlatformVersion Include=""222.0"" /> |
| 112 | + </ItemGroup> |
| 113 | + <PropertyGroup> |
| 114 | + <TargetPlatformVersion>111.0</TargetPlatformVersion> |
| 115 | + <TargetPlatformIdentifier>ios</TargetPlatformIdentifier> |
| 116 | + <TargetPlatformSupported>true</TargetPlatformSupported> |
| 117 | + </PropertyGroup> |
| 118 | +</Project> |
| 119 | +"; |
| 120 | + |
| 121 | + File.WriteAllText(Path.Combine(testAsset.TestRoot, "Directory.Build.targets"), DirectoryBuildTargetsContent); |
| 122 | + |
| 123 | + var buildCommand = new BuildCommand(testAsset); |
| 124 | + buildCommand.Execute() |
| 125 | + .Should() |
| 126 | + .Fail() |
| 127 | + .And |
| 128 | + .HaveStdOutContaining("NETSDK1140") |
| 129 | + .And |
| 130 | + .HaveStdOutContaining(string.Format(Strings.InvalidTargetPlatformVersion, "111.0", "ios", "222.0").Split ('\n', '\r') [0]) |
| 131 | + .And |
| 132 | + .HaveStdOutContaining("222.0"); |
| 133 | + } |
| 134 | + |
| 135 | + [Fact] |
| 136 | + public void It_fails_if_targetplatformversion_is_invalid() |
| 137 | + { |
| 138 | + var testProject = new TestProject() |
| 139 | + { |
| 140 | + Name = "It_fails_if_targetplatformversion_is_invalid", |
| 141 | + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, |
| 142 | + }; |
| 143 | + var testAsset = _testAssetsManager.CreateTestProject(testProject); |
| 144 | + |
| 145 | + |
| 146 | + string DirectoryBuildTargetsContent = $@" |
| 147 | +<Project> |
| 148 | + <ItemGroup> |
| 149 | + <SdkSupportedTargetPlatformVersion Include=""222.0"" /> |
| 150 | + </ItemGroup> |
| 151 | + <PropertyGroup> |
| 152 | + <TargetPlatformVersion>111.0</TargetPlatformVersion> |
| 153 | + <TargetPlatformIdentifier>ios</TargetPlatformIdentifier> |
| 154 | + <TargetPlatformSupported>true</TargetPlatformSupported> |
| 155 | + </PropertyGroup> |
| 156 | +</Project> |
| 157 | +"; |
| 158 | + |
| 159 | + File.WriteAllText(Path.Combine(testAsset.TestRoot, "Directory.Build.targets"), DirectoryBuildTargetsContent); |
| 160 | + |
| 161 | + var buildCommand = new BuildCommand(testAsset); |
| 162 | + buildCommand.Execute() |
| 163 | + .Should() |
| 164 | + .Fail() |
| 165 | + .And |
| 166 | + .HaveStdOutContaining("NETSDK1140") |
| 167 | + .And |
| 168 | + .HaveStdOutContaining(string.Format(Strings.InvalidTargetPlatformVersion, "111.0", "ios", "222.0").Split ('\n', '\r') [0]) |
| 169 | + .And |
| 170 | + .HaveStdOutContaining("222.0"); |
| 171 | + } |
93 | 172 | }
|
94 | 173 | }
|
0 commit comments