Skip to content

Commit

Permalink
Support net6 (#915)
Browse files Browse the repository at this point in the history
* Updated all targets and conditional compiles to net6

* Updated all targets and conditional compiles to net6

* Updated benchmarks project

* Added net5 download to support targets

* Updated dotnet 5 version

* Update .net version warnings

* Update IIDOptimizer to support net6
  • Loading branch information
ujjwalchadha authored Jul 23, 2021
1 parent 72ba46d commit b52b1e6
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 51 deletions.
6 changes: 3 additions & 3 deletions src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<Platforms>x64;x86</Platforms>
<TargetFrameworks>netcoreapp2.0;netcoreapp3.1;net5.0;</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<UseWinmd>false</UseWinmd>
<BenchmarkWinmdSupport Condition="'$(BenchmarkWinmdSupport)' == ''">false</BenchmarkWinmdSupport>
<!-- Controls whether to build using WinMDs or the projection. -->
<UseWinmd Condition="'$(TargetFramework)' == 'netcoreapp3.1' And $(BenchmarkWinmdSupport) == true">true</UseWinmd>
<ApplicationManifest Condition="$(UseWinmd) == true">Benchmarks.manifest</ApplicationManifest>
<BenchmarkTargetFramework>$(TargetFramework)</BenchmarkTargetFramework>
<BenchmarkTargetFramework Condition="'$(BenchmarkTargetFramework)' != 'net5.0'">netstandard2.0</BenchmarkTargetFramework>
<BenchmarkTargetFramework>netstandard2.0</BenchmarkTargetFramework>
<BenchmarkTargetFramework Condition="$(IsTargetFrameworkNet5OrGreater)">$(TargetFramework)</BenchmarkTargetFramework>
<IsDotnetBuild Condition="'$(IsDotnetBuild)' == ''">false</IsDotnetBuild>
<LangVersion Condition="$(IsDotnetBuild) == true">9.0</LangVersion>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using BenchmarkDotNet.Characteristics;
using System.IO;

#if NET5_0
#if NET
[assembly: global::System.Runtime.Versioning.SupportedOSPlatform("Windows10.0.10240.0")]
#endif

Expand Down
2 changes: 2 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<PlatformToolset>v142</PlatformToolset>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<AssetTargetFallback>netcoreapp5.0</AssetTargetFallback>
<IsTargetFrameworkNet5OrGreater>false</IsTargetFrameworkNet5OrGreater>
<IsTargetFrameworkNet5OrGreater Condition="'$(TargetFramework)' == 'net5.0' Or '$(TargetFramework)' == 'net6.0'">true</IsTargetFrameworkNet5OrGreater>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'net5.0'">
Expand Down
2 changes: 1 addition & 1 deletion src/Projections/Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Projections/Benchmark/Module.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if NET5_0
#if NET
using System.Runtime.Versioning;
[assembly: SupportedOSPlatform("Windows")]
#endif
6 changes: 3 additions & 3 deletions src/Projections/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<SimulateCsWinRTNugetReference>true</SimulateCsWinRTNugetReference>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' != 'net5.0' AND '$(TargetFramework)' != ''">
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<PropertyGroup Condition="!$(IsTargetFrameworkNet5OrGreater) AND '$(TargetFramework)' != ''">
<CsWinRTIIDOptimizerOptOut>true</CsWinRTIIDOptimizerOptOut>
</PropertyGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

</Project>
2 changes: 1 addition & 1 deletion src/Projections/Reunion/Reunion.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
<AssemblyName>Microsoft.WinUI</AssemblyName>
<AssemblyVersion>9.9.9.9</AssemblyVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Projections/Test/Test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Projections/WinUI/Module.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#if NET5_0
#if NET
[assembly: global::System.Runtime.Versioning.SupportedOSPlatform("Windows10.0.10240.0")]
#endif
2 changes: 1 addition & 1 deletion src/Projections/WinUI/WinUI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Projections/Windows/Windows.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
<AssemblyName>Microsoft.Windows.SDK.NET</AssemblyName>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/DiagnosticTests/DiagnosticTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<TargetFrameworks>net5.0-windows10.0.19041.0;net6.0-windows10.0.19041.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
<TargetFrameworks>net5.0-windows10.0.19041.0;net6.0-windows10.0.19041.0</TargetFrameworks>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>ObjectLifetimeTests.Lifted</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
Expand Down
20 changes: 10 additions & 10 deletions src/Tests/UnitTest/TestComponentCSharp_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
using Windows.Security.Cryptography.Core;
using System.Reflection;

#if NET5_0
#if NET
using WeakRefNS = System;
#else
using WeakRefNS = WinRT;
#endif

#if NET5_0
#if NET
// Test SupportedOSPlatform warnings for APIs targeting 10.0.19041.0:
[assembly: global::System.Runtime.Versioning.SupportedOSPlatform("Windows10.0.18362.0")]
#endif
Expand Down Expand Up @@ -403,7 +403,7 @@ public void TestReadOnlyDictionaryLookup()
Assert.True(LookupPorts().Wait(5000));
}

#if NET5_0
#if NET
async Task InvokeStreamWriteZeroBytes()
{
var random = new Random(42);
Expand Down Expand Up @@ -717,10 +717,10 @@ public void TestCustomProjections()
Assert.Equal("name", propertyName);

bool eventCalled = false;
TestObject.CanExecuteChanged += (object sender, EventArgs e) =>
{
eventCalled = true;
};
TestObject.CanExecuteChanged += (object sender, EventArgs e) =>
{
eventCalled = true;
};

TestObject.RaiseCanExecuteChanged();
Assert.True(eventCalled);
Expand All @@ -734,8 +734,8 @@ public void TestCustomProjections()
// Ensure robustness with bad runtime class names (parsing errors, type not found, etc)
var badRuntimeClassName = Class.BadRuntimeClassName;
Assert.NotNull(badRuntimeClassName);
}

}

[Fact]
public void TestKeyValuePair()
{
Expand Down Expand Up @@ -2483,7 +2483,7 @@ void Class_StaticIntPropertyChanged(object sender, int e)
Assert.True(eventCalled);
}

#if NET5_0
#if NET
[TestComponentCSharp.Warning] // NO warning CA1416
class WarningManaged { };

Expand Down
4 changes: 2 additions & 2 deletions src/Tests/UnitTest/UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<!--Target .NET Core 2.0 to test .NET Standard 2.0 projection -->
<TargetFrameworks>netcoreapp2.0;net5.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
<ProjectName>UnitTest</ProjectName>
<NoWarn>1701;1702;0436;1658</NoWarn>
Expand Down Expand Up @@ -36,7 +36,7 @@
<None Include="**/*.net5.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<ItemGroup Condition="$(IsTargetFrameworkNet5OrGreater)">
<Compile Remove="**/*.netcoreapp2.0.cs" />
<None Include="**/*.netcoreapp2.0.cs" />
</ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions src/WinRT.Runtime/AgileReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public unsafe AgileReference(IObjectReference instance)
ref iid,
instance.ThisPtr,
&agileReference));
#if NET5_0
#if NET
_agileReference = (IAgileReference)new SingleInterfaceOptimizedObject(typeof(IAgileReference), ObjectReference<ABI.WinRT.Interop.IAgileReference.Vftbl>.Attach(ref agileReference));
#else
_agileReference = ABI.WinRT.Interop.IAgileReference.FromAbi(agileReference).AsType<ABI.WinRT.Interop.IAgileReference>();
#endif
}
catch(TypeLoadException)
{
_cookie = Git.Value.RegisterInterfaceInGlobal(instance, iid);
_cookie = Git.Value.RegisterInterfaceInGlobal(instance, iid);
}
finally
{
Expand All @@ -51,14 +51,14 @@ protected virtual void Dispose(bool disposing)
if (!disposed)
{
if (_cookie != IntPtr.Zero)
{
try
{
Git.Value.RevokeInterfaceFromGlobal(_cookie);
{
try
{
Git.Value.RevokeInterfaceFromGlobal(_cookie);
}
catch(ArgumentException)
{
// Revoking cookie from GIT table may fail if apartment is gone.
{
// Revoking cookie from GIT table may fail if apartment is gone.
}
}
disposed = true;
Expand Down
8 changes: 4 additions & 4 deletions src/WinRT.Runtime/WinRT.Runtime.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net6.0</TargetFrameworks>
<RootNamespace>WinRT</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>9</LangVersion>
Expand Down Expand Up @@ -32,7 +32,7 @@
<None Include="**/*.net5.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<ItemGroup Condition="$(IsTargetFrameworkNet5OrGreater)">
<Compile Remove="**/*.netstandard2.0.cs" />
<None Include="**/*.netstandard2.0.cs" />
</ItemGroup>
Expand All @@ -52,7 +52,7 @@
<CsWinRTApiCompatVersion>1.0.1</CsWinRTApiCompatVersion>
<ApiCompatArgs>$(ApiCompatArgs) --allow-default-interface-methods</ApiCompatArgs>
<MatchingRefApiCompatArgs>$(MatchingRefApiCompatArgs) --allow-default-interface-methods</MatchingRefApiCompatArgs>
</PropertyGroup>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
<PackageReference Include="Microsoft.DotNet.ApiCompat" Version="5.0.0-beta.20560.3" PrivateAssets="All" />
Expand Down
20 changes: 16 additions & 4 deletions src/build.cmd
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
@echo off
if /i "%cswinrt_echo%" == "on" @echo on

set CsWinRTNet5SdkVersion=5.0.300
set CsWinRTBuildNetSDKVersion=6.0.100-preview.6.21355.2
set CsWinRTNet5SdkVersion=5.0.302
set this_dir=%~dp0

:dotnet
rem Install required .NET 5 SDK version and add to environment
rem Install required .NET SDK version and add to environment
set DOTNET_ROOT=%LocalAppData%\Microsoft\dotnet
set DOTNET_ROOT(86)=%LocalAppData%\Microsoft\dotnet\x86
set path=%DOTNET_ROOT%;%path%


rem Install .net5 to run our projects targeting it
powershell -NoProfile -ExecutionPolicy unrestricted -Command ^
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ^
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) ^
Expand All @@ -21,13 +22,24 @@ powershell -NoProfile -ExecutionPolicy unrestricted -Command ^
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) ^
-Version '%CsWinRTNet5SdkVersion%' -InstallDir '%DOTNET_ROOT(86)%' -Architecture 'x86' ^
-AzureFeed 'https://dotnetcli.blob.core.windows.net/dotnet'
rem Install .NET Version used to build projection
powershell -NoProfile -ExecutionPolicy unrestricted -Command ^
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ^
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) ^
-Version '%CsWinRTBuildNetSDKVersion%' -InstallDir '%DOTNET_ROOT%' -Architecture 'x64' ^
-AzureFeed 'https://dotnetcli.blob.core.windows.net/dotnet'
powershell -NoProfile -ExecutionPolicy unrestricted -Command ^
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ^
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) ^
-Version '%CsWinRTBuildNetSDKVersion%' -InstallDir '%DOTNET_ROOT(86)%' -Architecture 'x86' ^
-AzureFeed 'https://dotnetcli.blob.core.windows.net/dotnet'

:globaljson
rem Create global.json for current .NET SDK, and with allowPrerelease=true
set global_json=%this_dir%global.json
echo { > %global_json%
echo "sdk": { >> %global_json%
echo "version": "%CsWinRTNet5SdkVersion%", >> %global_json%
echo "version": "%CsWinRTBuildNetSDKVersion%", >> %global_json%
echo "allowPrerelease": true >> %global_json%
echo } >> %global_json%
echo } >> %global_json%
Expand Down
5 changes: 3 additions & 2 deletions src/cswinrt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace cswinrt
{ "output", 0, 1, "<path>", "Location of generated projection" },
{ "include", 0, option::no_max, "<prefix>", "One or more prefixes to include in projection" },
{ "exclude", 0, option::no_max, "<prefix>", "One or more prefixes to exclude from projection" },
{ "target", 0, 1, "<net5.0|netstandard2.0>", "Target TFM for projection. Omit for compatibility with newest TFM (net5.0)." },
{ "target", 0, 1, "<net6.0|net5.0|netstandard2.0>", "Target TFM for projection. Omit for compatibility with newest TFM (net5.0)." },
{ "component", 0, 0, {}, "Generate component projection." },
{ "verbose", 0, 0, {}, "Show detailed progress information" },
{ "help", 0, option::no_max, {}, "Show detailed help" },
Expand Down Expand Up @@ -86,7 +86,7 @@ Where <spec> is one or more of:

settings.verbose = args.exists("verbose");
auto target = args.value("target");
if (!target.empty() && target != "netstandard2.0" && !starts_with(target, "net5.0"))
if (!target.empty() && target != "netstandard2.0" && !starts_with(target, "net5.0") && !starts_with(target, "net6.0"))
{
throw usage_exception();
}
Expand Down Expand Up @@ -386,6 +386,7 @@ Where <spec> is one or more of:
}
catch (usage_exception const&)
{
result = 1;
print_usage(w);
}
catch (std::exception const& e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace System
using global::System.Runtime.InteropServices;
using global::System.Threading;
using global::System.Threading.Tasks;
using global::Windows.Foundation;

#if NET5_0
using global::Windows.Foundation;

#if NET
[global::System.Runtime.Versioning.SupportedOSPlatform("windows10.0.10240.0")]
#endif
public static class WindowsRuntimeSystemExtensions
Expand Down Expand Up @@ -232,7 +232,7 @@ struct VoidValueTypeParameter { }
/// using <code>VoidValueTypeParameter</code> offers better performance.</summary>
internal class VoidReferenceTypeParameter { }

#if NET5_0
#if NET
[global::System.Runtime.Versioning.SupportedOSPlatform("windows10.0.10240.0")]
#endif
sealed class AsyncInfoToTaskBridge<TResult, TProgress> : TaskCompletionSource<TResult>
Expand Down

0 comments on commit b52b1e6

Please sign in to comment.