Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>255eea008147245df48aaa1fae60eb92519f1dc3</Sha>
</Dependency>
<Dependency Name="Microsoft.WindowsDesktop.App" Version="5.0.0-preview.8.20352.5">
<Dependency Name="Microsoft.WindowsDesktop.App" Version="5.0.0-preview.8.20358.1">
<Uri>https://github.com/dotnet/windowsdesktop</Uri>
<Sha>37c6a8e306022848c661d9e38b99633f1ce11141</Sha>
<Sha>47d20bf0c3dd54f84e678c987db33c7ac95bb2f6</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Sdk.WindowsDesktop" Version="5.0.0-preview.8.20352.4" CoherentParentDependency="Microsoft.WindowsDesktop.App">
<Dependency Name="Microsoft.NET.Sdk.WindowsDesktop" Version="5.0.0-preview.8.20358.1" CoherentParentDependency="Microsoft.WindowsDesktop.App">
<Uri>https://github.com/dotnet/wpf</Uri>
<Sha>e7cad628c82f8761cac2070c80601ae8e75139a6</Sha>
<Sha>e36c6981d99317ffdfe0bcc9f1f264f59a29793d</Sha>
</Dependency>
<Dependency Name="Microsoft.AspNetCore.Analyzers" Version="5.0.0-preview.8.20359.6">
<Uri>https://github.com/dotnet/aspnetcore</Uri>
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/wpf -->
<MicrosoftNETSdkWindowsDesktopPackageVersion>5.0.0-preview.8.20352.4</MicrosoftNETSdkWindowsDesktopPackageVersion>
<MicrosoftNETSdkWindowsDesktopPackageVersion>5.0.0-preview.8.20358.1</MicrosoftNETSdkWindowsDesktopPackageVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/windowsdesktop -->
<MicrosoftWindowsDesktopAppVersion>5.0.0-preview.8.20352.5</MicrosoftWindowsDesktopAppVersion>
<MicrosoftWindowsDesktopAppVersion>5.0.0-preview.8.20358.1</MicrosoftWindowsDesktopAppVersion>
</PropertyGroup>
<!-- Get .NET Framework reference assemblies from NuGet packages -->
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.PackTool.props" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.PackProjectTool.props" />

<Import Project="$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.props" Condition="'$(_MicrosoftWindowsDesktopSdkImported)' != 'true'"/>
<Import Project="$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.props"/>
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Windows.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -992,5 +992,5 @@ Copyright (c) .NET Foundation. All rights reserved.
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.ILLink.targets" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.Analyzers.targets" Condition="'$(Language)' == 'C#' or '$(Language)' == 'VB'" />
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Windows.targets" Condition="'$(TargetPlatformIdentifier)' == 'Windows'" />
<Import Project="$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets" Condition="'$(ImportWindowsDesktopTargets)' == 'true' and '$(_MicrosoftWindowsDesktopSdkImported)' != 'true'"/>
<Import Project="$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets" Condition="'$(ImportWindowsDesktopTargets)' == 'true'"/>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,141 @@ public void It_does_not_download_desktop_runtime_packs_on_unix()
.NotHaveSubDirectories($"runtime.{Rid}.microsoft.windowsdesktop.app");
}

[Theory]
[InlineData("net5.0", "TargetPlatformIdentifier", "Windows", "WinExe")]
[InlineData("netcoreapp3.1", "UseWindowsForms", "true", "WinExe")]
[InlineData("netcoreapp3.1", "UseWPF", "true", "WinExe")]
[InlineData("netcoreapp3.1", "UseWPF", "false", "Exe")]
public void It_infers_WinExe_output_type(string targetFramework, string propName, string propValue, string expectedOutputType)
{
var testProject = new TestProject()
{
Name = "WinExeOutput",
TargetFrameworks = targetFramework,
IsSdkProject = true,
IsExe = true,
};
testProject.AdditionalProperties[propName] = propValue;
testProject.AdditionalProperties["TargetPlatformVersion"] = "7.0"; // Ensure TargetPlatformVersion is set so we can build with a TargetPlatformIdentifier

var asset = _testAssetsManager.CreateTestProject(testProject);

var getValuesCommand = new GetValuesCommand(asset, "OutputType");
getValuesCommand
.Execute()
.Should()
.Pass();

var values = getValuesCommand.GetValues();
values.Count.Should().Be(1);
values.First().Should().Be(expectedOutputType);
}

[WindowsOnlyFact]
public void It_builds_on_windows_with_the_windows_desktop_sdk_5_0_with_ProjectSdk_set()
{
const string ProjectName = "WindowsDesktopSdkTest_50";

const string tfm = "net5.0";

var testProject = new TestProject()
{
Name = ProjectName,
TargetFrameworks = tfm,
IsSdkProject = true,
ProjectSdk = "Microsoft.NET.Sdk.WindowsDesktop",
IsWinExe = true,
};

testProject.SourceFiles.Add("App.xaml.cs", _fileUseWindowsType);
testProject.AdditionalProperties.Add("UseWPF", "true");

var asset = _testAssetsManager.CreateTestProject(testProject);

var command = new BuildCommand(Log, Path.Combine(asset.Path, ProjectName));

command
.Execute()
.Should()
.Pass();
}

[WindowsOnlyFact]
public void It_builds_on_windows_with_the_windows_desktop_sdk_5_0_without_ProjectSdk_set()
{
const string ProjectName = "WindowsDesktopSdkTest_without_ProjectSdk_set";

const string tfm = "net5.0";

var testProject = new TestProject()
{
Name = ProjectName,
TargetFrameworks = tfm,
IsSdkProject = true,
IsWinExe = true,
};

testProject.SourceFiles.Add("App.xaml.cs", _fileUseWindowsType);
testProject.AdditionalProperties.Add("UseWPF", "true");
testProject.AdditionalProperties.Add("TargetPlatformIdentifier", "Windows");

var asset = _testAssetsManager.CreateTestProject(testProject);

var command = new BuildCommand(Log, Path.Combine(asset.Path, ProjectName));

command
.Execute()
.Should()
.Pass();
}

[WindowsOnlyFact]
public void When_TargetPlatformVersion_is_set_higher_than_10_It_can_reference_cswinrt_api()
{
const string ProjectName = "WindowsDesktopSdkTest_without_ProjectSdk_set";

const string tfm = "net5.0";

var testProject = new TestProject()
{
Name = ProjectName,
TargetFrameworks = tfm,
IsSdkProject = true,
IsWinExe = true,
};

testProject.SourceFiles.Add("Program.cs", _useCsWinrtApi);
testProject.AdditionalProperties.Add("TargetPlatformIdentifier", "Windows");
testProject.AdditionalProperties.Add("TargetPlatformVersion", "10.0.17763");

var asset = _testAssetsManager.CreateTestProject(testProject);

var buildCommand = new BuildCommand(Log, Path.Combine(asset.Path, ProjectName));

buildCommand.Execute()
.Should()
.Pass();

void Assert(DirectoryInfo outputDir)
{
outputDir.File("Microsoft.Windows.SDK.NET.dll").Exists.Should().BeTrue("The output has cswinrt dll");
outputDir.File("WinRT.Runtime.dll").Exists.Should().BeTrue("The output has cswinrt dll");
var runtimeconfigjson = File.ReadAllText(outputDir.File(ProjectName + ".runtimeconfig.json").FullName);
runtimeconfigjson.Contains(@"""name"": ""Microsoft.NETCore.App""").Should().BeTrue("runtimeconfig.json only reference Microsoft.NETCore.App");
runtimeconfigjson.Contains("Microsoft.Windows.SDK.NET").Should().BeFalse("runtimeconfig.json does not reference windows SDK");
}

Assert(buildCommand.GetOutputDirectory(tfm));

var publishCommand = new PublishCommand(Log, Path.Combine(asset.Path, ProjectName));
var runtimeIdentifier = "win-x64";
publishCommand.Execute("-p:SelfContained=true", $"-p:RuntimeIdentifier={runtimeIdentifier}")
.Should()
.Pass();

Assert(publishCommand.GetOutputDirectory(tfm, runtimeIdentifier: runtimeIdentifier));
}

private TestAsset CreateWindowsDesktopSdkTestAsset(string projectName, string uiFrameworkProperty)
{
const string tfm = "netcoreapp3.0";
Expand Down Expand Up @@ -189,34 +324,39 @@ private TestAsset CreateWindowsDesktopReferenceTestAsset(string projectName, str
return _testAssetsManager.CreateTestProject(testProject);
}

[Theory]
[InlineData("net5.0", "TargetPlatformIdentifier", "Windows", "WinExe")]
[InlineData("netcoreapp3.1", "UseWindowsForms", "true", "WinExe")]
[InlineData("netcoreapp3.1", "UseWPF", "true", "WinExe")]
[InlineData("netcoreapp3.1", "UseWPF", "false", "Exe")]
public void It_infers_WinExe_output_type(string targetFramework, string propName, string propValue, string expectedOutputType)
{
var testProject = new TestProject()
{
Name = "WinExeOutput",
TargetFrameworks = targetFramework,
IsSdkProject = true,
IsExe = true,
};
testProject.AdditionalProperties[propName] = propValue;
testProject.AdditionalProperties["TargetPlatformVersion"] = "7.0"; // Ensure TargetPlatformVersion is set so we can build with a TargetPlatformIdentifier
private readonly string _fileUseWindowsType = @"
using System.Windows;

var asset = _testAssetsManager.CreateTestProject(testProject);
namespace wpf
{
public partial class App : Application
{
}

var getValuesCommand = new GetValuesCommand(asset, "OutputType");
getValuesCommand
.Execute()
.Should()
.Pass();
class Program
{
static void Main(string[] args)
{
}
}
}
";

var values = getValuesCommand.GetValues();
values.Count.Should().Be(1);
values.First().Should().Be(expectedOutputType);
private readonly string _useCsWinrtApi = @"
using System;
using Windows.Data.Json;

namespace consolecswinrt
{
class Program
{
static void Main(string[] args)
{
var rootObject = JsonObject.Parse(""{\""greet\"": \""Hello\""}"");
Console.WriteLine(rootObject[""greet""]);
}
}
}
";
}
}