From 3a3d349b6a42b056f3224ceedba302cbedbd80f6 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 21 Jan 2021 20:22:42 -0800 Subject: [PATCH 1/4] Fix issue where UseWPF / UseWindowsForms wouldn't work in Directory.Build.targets --- .../targets/Microsoft.NET.Sdk.BeforeCommon.targets | 14 +------------- .../targets/Microsoft.NET.Sdk.targets | 12 ++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index c537695da869..0bb228e3434c 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -71,19 +71,7 @@ Copyright (c) .NET Foundation. All rights reserved. - - - - true - true - - - $(AfterMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets - - + + + true + true + + + $(AfterMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets + + From 0ac96b472cf55be85de895148d1205ad76c26e37 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 21 Jan 2021 20:23:07 -0800 Subject: [PATCH 2/4] Add test for setting UseWPF in Directory.Build.targets --- ...ThatWeWantToBuildAWindowsDesktopProject.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs index 5c3c9c24ff66..406243773173 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs @@ -237,5 +237,43 @@ public void It_fails_if_target_platform_identifier_and_version_are_invalid() .And .NotHaveStdOutContaining("NETSDK1140"); } + + [WindowsOnlyFact] + public void UseWPFCanBeSpecifiedInDirectoryBuildTargets() + { + var testDir = _testAssetsManager.CreateTestDirectory(); + + var newCommand = new DotnetCommand(Log); + newCommand.WorkingDirectory = testDir.Path; + + newCommand.Execute("new", "wpf", "--debug:ephemeral-hive").Should().Pass(); + + var projectPath = Path.Combine(testDir.Path, Path.GetFileName(testDir.Path) + ".csproj"); + + var project = XDocument.Load(projectPath); + var ns = project.Root.Name.Namespace; + + project.Root.Element(ns + "PropertyGroup") + .Element(ns + "UseWPF") + .Remove(); + + project.Save(projectPath); + + string DirectoryBuildTargetsContent = @" + + + true + + +"; + + File.WriteAllText(Path.Combine(testDir.Path, "Directory.Build.targets"), DirectoryBuildTargetsContent); + + var buildCommand = new BuildCommand(Log, testDir.Path); + + buildCommand.Execute() + .Should() + .Pass(); + } } } From 98a8091c4343ffccb7e1b09ac7aefb34f7ffbfb7 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Sat, 23 Jan 2021 19:04:27 -0800 Subject: [PATCH 3/4] Fix setting various platform version properties in Directory.Build.targets --- .../Microsoft.NET.Sdk.BeforeCommon.targets | 13 ------------- .../targets/Microsoft.NET.Sdk.targets | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index 0bb228e3434c..0626e0520143 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -70,19 +70,6 @@ Copyright (c) .NET Foundation. All rights reserved. - - - - - 0.0 - - - $(TargetPlatformVersion) - - diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets index 812621685d6d..fdf13ed701b5 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets @@ -1075,5 +1075,24 @@ Copyright (c) .NET Foundation. All rights reserved. $(AfterMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets + + + + + + 0.0 + $(TargetPlatformIdentifier),Version=$(TargetPlatformVersion) + $([Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKDisplayName($(TargetPlatformIdentifier), $(TargetPlatformVersion))) + + + + + $(TargetPlatformVersion) + + From 6b3d5a9f37adf04b3beb3d86b4265963485c84a8 Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Sat, 23 Jan 2021 19:04:50 -0800 Subject: [PATCH 4/4] Add tests for setting platform version properties in Directory.Build.targets --- ...ThatWeWantToBuildAWindowsDesktopProject.cs | 79 ++++++++++++++++++- 1 file changed, 78 insertions(+), 1 deletion(-) diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs index 406243773173..c5acda77a849 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildAWindowsDesktopProject.cs @@ -239,7 +239,7 @@ public void It_fails_if_target_platform_identifier_and_version_are_invalid() } [WindowsOnlyFact] - public void UseWPFCanBeSpecifiedInDirectoryBuildTargets() + public void UseWPFCanBeSetInDirectoryBuildTargets() { var testDir = _testAssetsManager.CreateTestDirectory(); @@ -275,5 +275,82 @@ public void UseWPFCanBeSpecifiedInDirectoryBuildTargets() .Should() .Pass(); } + + [WindowsOnlyFact] + public void TargetPlatformVersionCanBeSetInDirectoryBuildTargets() + { + var testProject = new TestProject() + { + TargetFrameworks = "net5.0-windows" + }; + + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + string targetPlatformVersion = "10.0.18362.0"; + + string DirectoryBuildTargetsContent = $@" + + + {targetPlatformVersion} + + +"; + + File.WriteAllText(Path.Combine(testAsset.TestRoot, "Directory.Build.targets"), DirectoryBuildTargetsContent); + + var buildCommand = new BuildCommand(testAsset); + buildCommand.Execute() + .Should() + .Pass(); + + GetPropertyValue(testAsset, "SupportedOSPlatformVersion").Should().Be(targetPlatformVersion); + GetPropertyValue(testAsset, "TargetPlatformMinVersion").Should().Be(targetPlatformVersion); + GetPropertyValue(testAsset, "TargetPlatformMoniker").Should().Be($"Windows,Version={targetPlatformVersion}"); + } + + [WindowsOnlyFact] + public void SupportedOSPlatformVersionCanBeSetInDirectoryBuildTargets() + { + var testProject = new TestProject() + { + TargetFrameworks = "net5.0-windows10.0.19041.0" + }; + + var testAsset = _testAssetsManager.CreateTestProject(testProject); + + string supportedOSPlatformVersion = "10.0.18362.0"; + + string DirectoryBuildTargetsContent = $@" + + + {supportedOSPlatformVersion} + + +"; + + File.WriteAllText(Path.Combine(testAsset.TestRoot, "Directory.Build.targets"), DirectoryBuildTargetsContent); + + var buildCommand = new BuildCommand(testAsset); + buildCommand.Execute() + .Should() + .Pass(); + + GetPropertyValue(testAsset, "SupportedOSPlatformVersion").Should().Be(supportedOSPlatformVersion); + GetPropertyValue(testAsset, "TargetPlatformMinVersion").Should().Be(supportedOSPlatformVersion); + GetPropertyValue(testAsset, "TargetPlatformVersion").Should().Be("10.0.19041.0"); + GetPropertyValue(testAsset, "TargetPlatformMoniker").Should().Be("Windows,Version=10.0.19041.0"); + } + + + private string GetPropertyValue(TestAsset testAsset, string propertyName) + { + var getValueCommand = new GetValuesCommand(testAsset, propertyName); + getValueCommand.Execute() + .Should() + .Pass(); + + return getValueCommand.GetValues().Single(); + } + } }