Skip to content

Commit

Permalink
Make CsWinRT build with VS 2022 (#1217)
Browse files Browse the repository at this point in the history
* Fix project references from native to managed projections which broke with VS 2022

* Update .NET versions

* Update VS version

* Couple more versions

* Update CsWinRT-Build-Steps.yml

* Use latest

* Fix version

* Use .NET Core 3.1 for NET standard testing

* use V143 when available

* Try getting x86 working

* Experiment

* Fix indenting

* Fix benchmarks

* Fix benchmarks

* Update to latest versions and doc updates
  • Loading branch information
manodasanW authored Jul 11, 2022
1 parent e54aaea commit 28be51f
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 96 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Below is our guidance for how to build the repo, report issues, propose new feat

C#/WinRT currently requires the following packages, or newer, to build:

- [Visual Studio 16.8](https://visualstudio.microsoft.com/downloads/)
- [.NET 5.0 SDK](https://dotnet.microsoft.com/download/dotnet/5.0)
- [.NET Core 2.1 SDK](https://dotnet.microsoft.com/download/dotnet-core/2.1)
- [Visual Studio 17.0](https://visualstudio.microsoft.com/downloads/)
- [.NET 6.0 SDK](https://dotnet.microsoft.com/download/dotnet/6.0)
- [.NET Core 3.1 SDK](https://dotnet.microsoft.com/download/dotnet-core/3.1)
- [nuget.exe 5.8.0-preview.3](https://www.nuget.org/downloads)
- Microsoft.WinUI 3.0.0-preview4.210210.4

The [`build.cmd`](src/build.cmd) script takes care of all related configuration steps and is the simplest way to get started building C#/WinRT. It installs prerequisites such as `nuget.exe` and the .NET 5 SDK, configures the environment to use .NET 5 (creating a `global.json` if necessary), builds the compiler, and builds and executes the unit tests. To build C#/WinRT, follow these steps:
The [`build.cmd`](src/build.cmd) script takes care of all related configuration steps and is the simplest way to get started building C#/WinRT. It installs prerequisites such as `nuget.exe` and the .NET 6 SDK, configures the environment to use .NET 6 (creating a `global.json` if necessary), builds the compiler, and builds and executes the unit tests. To build C#/WinRT, follow these steps:

- Open a Visual Studio Developer command prompt pointing at the repo.
- Run `src\build.cmd`.
Expand Down
21 changes: 4 additions & 17 deletions build/AzurePipelineTemplates/CsWinRT-Benchmarks-Steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,14 @@ steps:
script: get_testwinrt.cmd
workingDirectory: $(Build.SourcesDirectory)\src

# Use .NET Core SDK 2.1
# Use .NET Core SDK 3.1
- task: UseDotNet@2
displayName: Use .NET Core SDK 2.1
displayName: Use .NET Core SDK 3.1
inputs:
version: 2.1.x
version: 3.1.x
installationPath: C:\Users\VssAdministrator\AppData\Local\Microsoft\dotnet\
performMultiLevelLookup: true

# Install .NET 5 SDK
- task: PowerShell@2
displayName: Install .NET 5 SDK
inputs:
targetType: inline
failOnStderr: true
script: |
Write-Host ##vso[task.setvariable variable=PATH;]${env:LocalAppData}\Microsoft\dotnet;${env:PATH};
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Version "$($env:NET5_SDK_VERSION)" -Architecture "x64" -AzureFeed "$($env:NET5_SDK_FEED)"
# Install .NET 6 SDK
- task: PowerShell@2
displayName: Install .NET 6 SDK
Expand Down Expand Up @@ -63,7 +50,7 @@ steps:
script: |
if "%VSCMD_VER%"=="" (
pushd c:
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" >nul 2>&1
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" >nul 2>&1
popd
)
Expand Down
25 changes: 6 additions & 19 deletions build/AzurePipelineTemplates/CsWinRT-Build-Steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,14 @@ steps:
Write-Host ##vso[task.setvariable variable=PATH;]${env:Agent_TempDirectory}\procdump;${env:PATH};
# Use .NET Core SDK 2.1
# Use .NET Core SDK 3.1
- task: UseDotNet@2
displayName: Use .NET Core SDK 2.1
displayName: Use .NET Core SDK 3.1
inputs:
version: 2.1.x
version: 3.1.x
installationPath: C:\Users\VssAdministrator\AppData\Local\Microsoft\dotnet\
performMultiLevelLookup: true

# Install .NET 5 SDK
- task: PowerShell@2
displayName: Install .NET 5 SDK
inputs:
targetType: inline
failOnStderr: true
script: |
Write-Host ##vso[task.setvariable variable=PATH;]${env:LocalAppData}\Microsoft\dotnet;${env:PATH};
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Version "$($env:NET5_SDK_VERSION)" -Architecture "x64" -AzureFeed "$($env:NET5_SDK_FEED)"
# Install .NET 6 SDK
- task: PowerShell@2
displayName: Install .NET 6 SDK
Expand Down Expand Up @@ -128,7 +115,7 @@ steps:
script: |
if "%VSCMD_VER%"=="" (
pushd c:
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" >nul 2>&1
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" >nul 2>&1
popd
)
Expand All @@ -146,7 +133,7 @@ steps:
script: |
if "%VSCMD_VER%"=="" (
pushd c:
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" >nul 2>&1
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" >nul 2>&1
popd
)
Expand Down Expand Up @@ -405,4 +392,4 @@ steps:
condition: eq(variables['BuildConfiguration'],'Release')
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)\_manifest'
ArtifactName: SBOM_$(BuildPlatform)
ArtifactName: SBOM_$(BuildPlatform)
15 changes: 12 additions & 3 deletions build/AzurePipelineTemplates/CsWinRT-BuildAndTest-Stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ stages:
jobs:
- job: BuildAndTest
pool:
vmImage: windows-2019
vmImage: windows-latest
timeoutInMinutes: 90
# https://docs.microsoft.com/en-us/azure/devops/pipelines/process/phases?view=azure-devops&tabs=yaml#multi-job-configuration
strategy:
Expand Down Expand Up @@ -36,6 +36,15 @@ stages:
# Build Steps
- template: CsWinRT-Build-Steps.yml

# Set Dotnet paths
- task: PowerShell@2
displayName: Set DotNet paths
inputs:
targetType: inline
script: |
Write-Host "##vso[task.setvariable variable=DOTNET_ROOT;]C:\Users\VssAdministrator\AppData\Local\Microsoft\dotnet\"
Write-Host "##vso[task.setvariable variable=DOTNET_ROOT(x86);]C:\Users\VssAdministrator\AppData\Local\Microsoft\dotnet\x86\"
# Run Unit Tests
- task: DotNetCoreCLI@2
displayName: Run Unit Tests
Expand Down Expand Up @@ -109,7 +118,7 @@ stages:
condition: or(eq(variables['_RunBenchmarks'],'true'), eq(variables['Build.Reason'],'Schedule'))
dependsOn: []
pool:
vmImage: windows-2019
vmImage: windows-latest
timeoutInMinutes: 120
steps:
- template: CsWinRT-Benchmarks-Steps.yml
- template: CsWinRT-Benchmarks-Steps.yml
6 changes: 3 additions & 3 deletions build/AzurePipelineTemplates/CsWinRT-Variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ variables:
PatchVersion: 5
WinRT.Runtime.AssemblyVersion: '1.6.0.0'
Net5.SDK.Feed: 'https://dotnetcli.blob.core.windows.net/dotnet'
Net5.SDK.Version: '5.0.404'
Net6.SDK.Version: '6.0.101'
Net5.SDK.Version: '5.0.408'
Net6.SDK.Version: '6.0.301'
NoSamples: 'false'

# This 'coalesce' pattern allows the yml to define a default value for a variable but allows the value to be overridden at queue time.
# E.g. '_IsRelease' defaults to empty string, but if 'IsRelease' is set at queue time that value will be used.

_IsRelease: $[coalesce(variables.IsRelease, '')]
_RunBenchmarks: $[coalesce(variables.RunBenchmarks, 'false')]
_DotNetRuntimeVersion: $[coalesce(variables.DotNetRuntimeVersion, '5.0.13')]
_DotNetRuntimeVersion: $[coalesce(variables.DotNetRuntimeVersion, '5.0.17')]
_WindowsSdkVersionSuffix: $[coalesce(variables.WindowsSdkPackageVersionSuffix, '25')]
29 changes: 6 additions & 23 deletions src/Authoring/WinRT.Host/WinRT.Host.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,44 +34,32 @@
<RootNamespace>WinRTHost</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<PropertyGroup Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -289,11 +277,6 @@
<None Include="NetHostDir.csproj" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WinRT.Host.Shim\WinRT.Host.Shim.csproj">
<Project>{0bb8f82d-874e-45aa-bca3-20ce0562164a}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="WinRTHostErrorStrings.rc" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<BenchmarkTargetFramework Condition="$(IsTargetFrameworkNet5OrGreater)">$(TargetFramework)</BenchmarkTargetFramework>
<IsDotnetBuild Condition="'$(IsDotnetBuild)' == ''">false</IsDotnetBuild>
<LangVersion Condition="$(IsDotnetBuild) == true">9.0</LangVersion>
<DefineConstants Condition="$(UseWinmd) == true">USE_WINMD</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public CustomConfig()
new MsBuildArgument("/p:platform=x64"),
new MsBuildArgument("/p:IsDotnetBuild=true")
}
).AsDefault();

).AsDefault();

Config = Config.AddExporter(JsonExporter.Full);

// Test WinMD support
#if NETCOREAPP3_1
#if USE_WINMD
// BenchmarkDotNet will rebuild the project with a project reference to this project when this project's output exe is ran. It
// will be ran from the same folder as where we have the application manifest binplaced which we want to embed in the new exe.
string manifestFile = Path.Combine(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
<IsPackable>false</IsPackable>
<SimulateCsWinRTNugetReference>true</SimulateCsWinRTNugetReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<Keyword>Win32Proj</Keyword>
<RootNamespace>AuthoringConsumptionTest</RootNamespace>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<_WinMDPlatform>$(Platform)</_WinMDPlatform>
<_WinMDPlatform Condition="'$(Platform)' == 'Win32'">x86</_WinMDPlatform>
Expand Down Expand Up @@ -68,21 +69,26 @@
<ItemGroup>
<ProjectReference Include="..\..\Projections\Windows\Windows.csproj">
<Project>{ffa9a78b-f53f-43ee-af87-24a80f4c330a}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\..\Projections\WinUI\WinUI.csproj">
<Project>{0a991d5f-bfee-4d2f-9aad-6ad06470a5df}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\..\Authoring\WinRT.Host.Shim\WinRT.Host.Shim.csproj">
<Project>{0bb8f82d-874e-45aa-bca3-20ce0562164a}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\..\Authoring\WinRT.Host\WinRT.Host.vcxproj">
<Project>{7e33bcb7-19c5-4061-981d-ba695322708a}</Project>
</ProjectReference>
<ProjectReference Include="..\..\WinRT.Runtime\WinRT.Runtime.csproj">
<Project>{25244ced-966e-45f2-9711-1f51e951ff89}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\AuthoringTest\AuthoringTest.csproj">
<Project>{41e2a272-150f-42f5-ad40-047aad9088a0}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
<PropertyGroup>
<ProjectGuid>75b1621f-ec51-4d77-bd7e-bee576b3adc9</ProjectGuid>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<TargetPlatformVersion>10.0.19041.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<AppxPackageSigningEnabled>false</AppxPackageSigningEnabled>
Expand Down
8 changes: 7 additions & 1 deletion src/Tests/HostTest/HostTest.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<ProjectGuid>{b511b7c9-c8e2-47ed-a0d1-538c00747d30}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
Expand All @@ -58,21 +59,26 @@
<ItemGroup>
<ProjectReference Include="..\..\Projections\TestHost.ProbeByClass\TestHost.ProbeByClass.csproj">
<Project>{ef3326b5-716f-41d2-ab30-4efab30955e2}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\..\Projections\Test\Test.csproj">
<Project>{c6d580c5-7037-4733-b933-916ff400afe2}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\..\Projections\Windows\Windows.csproj">
<Project>{ffa9a78b-f53f-43ee-af87-24a80f4c330a}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\..\Authoring\WinRT.Host.Shim\WinRT.Host.Shim.csproj">
<Project>{0bb8f82d-874e-45aa-bca3-20ce0562164a}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
<ProjectReference Include="..\..\Authoring\WinRT.Host\WinRT.Host.vcxproj">
<Project>{7e33bcb7-19c5-4061-981d-ba695322708a}</Project>
</ProjectReference>
<ProjectReference Include="..\..\WinRT.Runtime\WinRT.Runtime.csproj">
<Project>{25244ced-966e-45f2-9711-1f51e951ff89}</Project>
<SetTargetFramework>TargetFramework=net5.0</SetTargetFramework>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/UnitTest/UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!--Target .NET Core 2.0 to test .NET Standard 2.0 projection -->
<TargetFrameworks>netcoreapp2.0;net5.0;net6.0</TargetFrameworks>
<!--Target .NET Core 3.1 to test .NET Standard 2.0 projection -->
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<Platforms>x64;x86</Platforms>
<ProjectName>UnitTest</ProjectName>
<NoWarn>1701;1702;0436;1658</NoWarn>
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark.cmd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
nuget restore TestWinRT\Test.sln
nuget restore cswinrt.sln
msbuild Benchmarks\Benchmarks.csproj -t:restore -t:build /p:platform=x64 /p:configuration=release /p:solutiondir=%~dp0 /p:IsDotnetBuild=false
dotnet %~dp0Benchmarks\bin\x64\Release\netcoreapp2.0\Benchmarks.dll -filter * --runtimes netcoreapp5.0
dotnet %~dp0Benchmarks\bin\x64\Release\netcoreapp3.1\Benchmarks.dll -filter * --runtimes netcoreapp5.0
nuget restore Perf\ResultsComparer\ResultsComparer.sln
msbuild Perf\ResultsComparer\ResultsComparer.sln -t:restore -t:build /p:platform="Any CPU" /p:configuration=release
set baselinedir=%1
Expand Down
Loading

0 comments on commit 28be51f

Please sign in to comment.