Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address ComWrappers breaking change and add prerelease policy #321

Merged
merged 5 commits into from
Jun 17, 2020
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ _build/
global.json
.nuget
.nupkg
nuget/Microsoft.Windows.CsWinRT.Prerelease.targets
3 changes: 3 additions & 0 deletions Projections/Test/Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<!--Remove references to projection source winmds to prevent compile conflict warnings-->
<ReferencePathWithRefAssemblies Remove="@(ReferencePathWithRefAssemblies)" Condition="%(ReferencePathWithRefAssemblies.Filename) == 'TestComponent'" />
<ReferencePathWithRefAssemblies Remove="@(ReferencePathWithRefAssemblies)" Condition="%(ReferencePathWithRefAssemblies.Filename) == 'TestComponentCSharp'" />
<!--Also remove ReferencePath winmds to prevent error NETSDK1130 false positive-->
<ReferencePath Remove="@(ReferencePath)" Condition="%(ReferencePath.Filename) == 'TestComponent'" />
<ReferencePath Remove="@(ReferencePath)" Condition="%(ReferencePath.Filename) == 'TestComponentCSharp'" />
</ItemGroup>
</Target>

Expand Down
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,15 @@ The following msbuild project fragment demonstrates a simple invocation of cswin
</Target>
```
# Building
C#/WinRT currently depends on a private prerelease WinUI 3 NuGet, which should be made public around //build. C#/WinRT also uses the .NET 5 preview SDK. This is public, but there are some related configuration steps. The build.cmd script takes care of all this, and is the simplest way to get started building C#/WinRT.

The build script is intended to be executed from a Visual Studio Developer command prompt. It installs prerequisites such as nuget 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.
C#/WinRT currently requires the following packages to build:
- Visual Studio 16.6 (more specifically, MSBuild 16.6.0 for "net5.0" TFM support)
- .NET 5 SDK 5.0.100-preview.6.20314.3
- WinUI 3 3.0.0-preview1.200515.3

**Note:** As prereleases may make breaking changes before final release, any other combinations above may work but are not supported and will generate a build warning.

The build.cmd script takes care of all related configuration steps and is the simplest way to get started building C#/WinRT. The build script is intended to be executed from a Visual Studio Developer command prompt. It installs prerequisites such as nuget 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.

After a successful command-line build, the cswinrt.sln can be launched from the same command prompt, to inherit the necessary environment. By default, the UnitTest and WinUIProjection projections are only generated for Release configurations, where cswinrt.exe can execute in seconds. For Debug configurations, projection generation must be turned on with the project property GenerateTestProjection.

Expand All @@ -99,10 +105,6 @@ The **/WinRT.Runtime** folder contains the WinRT.Runtime project for building th

The **/nuget** folder contains source files for producing a C#/WinRT NuGet package, which is regularly built, signed, and published to nuget.org by Microsoft. The C#/WinRT NuGet package contains the cswinrt.exe compiler, and both versions of the winrt.runtime.dll.

## /UnitTest

The **/UnitTest** folder contains unit tests for validating the projection generated for the TestComponentCSharp project (below), for the TestWinRT\TestComponent project (below), and for foundational parts of the Windows SDK. All pull requests should ensure that this project executes without errors.

## /TestWinRT

C#/WinRT makes use of the standalone [TestWinRT](https://github.com/microsoft/TestWinRT/) repository for general language projection test coverage. This repo should be cloned into the root of the C#/WinRT repo, via **get_testwinrt.cmd**, so that the cswinrt.sln can resolve its reference to TestComponent.vcxproj. The resulting TestComponent.dll and TestComponent.winmd files are consumed by the UnitTest project above.
Expand All @@ -111,9 +113,17 @@ C#/WinRT makes use of the standalone [TestWinRT](https://github.com/microsoft/Te

The **/TestComponentCSharp** folder contains an implementation of a WinRT test component, defined in class.idl and used by the UnitTest project. To complement the general TestComponent above, the TestComponentCSharp tests scenarios specific to the C#/WinRT language projection.

## /WinUI
## /Projections

The **/Projections** folder contains several projects for generating and building projections from the Windows SDK, WinUI, and Test metadata (produced by the TestWinRT and TestComponentCSharp projects).

## /UnitTest

The **/UnitTest** folder contains unit tests for validating the Windows SDK, WinUI, and Test projections generated above. All pull requests should ensure that this project executes without errors.

## /WinUIDesktopSample

The **/WinUI** folder contains several related projects for generating and building a complete Windows SDK and WinUI projection, along with an end-to-end sample app that uses the generated projection. The projection is built out of **/winuiprojection**, which is consumed by both the sample app under **/winuidesktopsample**, and a simple test project under **/winuitest**.
The **/WinUIDesktopSample** contains an end-to-end sample app that uses the Windows SDK and WinUI projections generated above.

# Contributing

Expand Down
5 changes: 5 additions & 0 deletions UnitTest/UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
<!--Remove references to projection source winmds to prevent compile conflict warnings-->
<ReferencePathWithRefAssemblies Remove="@(ReferencePathWithRefAssemblies)" Condition="%(ReferencePathWithRefAssemblies.Filename) == 'TestComponent'" />
<ReferencePathWithRefAssemblies Remove="@(ReferencePathWithRefAssemblies)" Condition="%(ReferencePathWithRefAssemblies.Filename) == 'TestComponentCSharp'" />
<!--Also remove ReferencePath winmds to prevent error NETSDK1130 false positive-->
<ReferencePath Remove="@(ReferencePath)" Condition="%(ReferencePath.Filename) == 'TestComponent'" />
<ReferencePath Remove="@(ReferencePath)" Condition="%(ReferencePath.Filename) == 'TestComponentCSharp'" />
<!--Remove any ReferenceDependencyPaths winmds to prevent deps.json from failing unit test-->
<ReferenceDependencyPaths Remove="@(ReferenceDependencyPaths)" Condition="%(ReferenceDependencyPaths.Extension) == '.winmd'" />
</ItemGroup>
</Target>

Expand Down
14 changes: 8 additions & 6 deletions WinRT.Runtime/ComWrappersSupport.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ private static ComWrappers ComWrappers
{
if (_comWrappers is null)
{
_comWrappers = new DefaultComWrappers();
_comWrappers.RegisterAsGlobalInstance();
_comWrappers = new DefaultComWrappers();
ComWrappers.RegisterForTrackerSupport(_comWrappers);
ComWrappers.RegisterForMarshalling(_comWrappers);
}
return _comWrappers;
}
set
{
_comWrappers = value;
_comWrappers.RegisterAsGlobalInstance();
_comWrappers = value;
ComWrappers.RegisterForTrackerSupport(_comWrappers);
ComWrappers.RegisterForMarshalling(_comWrappers);
}
}

Expand Down Expand Up @@ -117,8 +119,8 @@ static DefaultComWrappers()
AddRef = Marshal.GetDelegateForFunctionPointer<IUnknownVftbl._AddRef>(addRef),
Release = Marshal.GetDelegateForFunctionPointer<IUnknownVftbl._Release>(release),
};
}

}
protected override unsafe ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count)
{
if (IsRuntimeImplementedRCW(obj))
Expand Down
27 changes: 20 additions & 7 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@echo off

set Net5SdkVersion=5.0.100-preview.4.20227.10
set CsWinRTNet5SdkVersion=5.0.100-preview.6.20314.3
set CsWinRTMSBuildVersion=16.6.0

:dotnet
rem Install required .NET 5 SDK version and add to environment
Expand All @@ -10,21 +11,21 @@ set path=%DOTNET_ROOT%;%path%
powershell -NoProfile -ExecutionPolicy unrestricted -Command ^
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; ^
&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) ^
-Version '%Net5SdkVersion%' -InstallDir "%DOTNET_ROOT%" -Architecture 'x64' ^
-Version '%CsWinRTNet5SdkVersion%' -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 '%Net5SdkVersion%' -InstallDir "%DOTNET_ROOT(86)%" -Architecture 'x86' ^
-Version '%CsWinRTNet5SdkVersion%' -InstallDir "%DOTNET_ROOT(86)%" -Architecture 'x86' ^
-AzureFeed 'https://dotnetcli.blob.core.windows.net/dotnet' "

:globaljson
rem User expected to provide global.json with allowPrerelease=true
if not exist %~dp0global.json (
echo global.json not found, creating one to allowPrelease for unit test project builds
echo Creating default global.json to allowPrelease for unit test project builds
echo { > global.json
echo "sdk": { >> global.json
echo "version": "%Net5SdkVersion%", >> global.json
echo "version": "%CsWinRTNet5SdkVersion%", >> global.json
echo "rollForward": "patch", >> global.json
echo "allowPrerelease": true >> global.json
echo } >> global.json
Expand All @@ -39,7 +40,7 @@ set cswinrt_platform=%1
set cswinrt_configuration=%2
set cswinrt_version_number=%3
set cswinrt_version_string=%4
set cswinrt_label=%5
set "%5"!="" set cswinrt_label=%5

if "%cswinrt_platform%"=="" set cswinrt_platform=x64

Expand Down Expand Up @@ -67,6 +68,18 @@ if "%cswinrt_configuration%"=="" (
if "%cswinrt_version_number%"=="" set cswinrt_version_number=0.0.0.0
if "%cswinrt_version_string%"=="" set cswinrt_version_string=0.0.0-private.0

rem Generate prerelease targets file to exercise build warnings
set prerelease_targets=nuget\Microsoft.Windows.CsWinRT.Prerelease.targets
if not exist %prerelease_targets% (
echo Creating default %prerelease_targets%
echo ^<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CsWinRTVerifyPrerelease"^> > %prerelease_targets%
echo ^<Target Name="CsWinRTVerifyPrerelease" >> %prerelease_targets%
echo ^Condition="'$(Net5SdkVersion)' ^!= '%CsWinRTNet5SdkVersion%' or '$(MSBuildVersion)' ^!= '%CsWinRTMSBuildVersion%'"^> >> %prerelease_targets%
echo ^<Warning Text="This C#/WinRT prerelease is designed for .Net SDK %CsWinRTNet5SdkVersion% and MSBuild %CsWinRTMSBuildVersion%. Other prerelease combinations may be incompatible due to breaking changes." /^> >> %prerelease_targets%
echo ^</Target^> >> %prerelease_targets%
echo ^</Project^> >> %prerelease_targets%
)

if not "%cswinrt_label%"=="" goto %cswinrt_label%

:restore
Expand All @@ -78,7 +91,7 @@ if not exist .nuget\nuget.exe powershell -Command "Invoke-WebRequest https://dis
:build
call get_testwinrt.cmd
echo Building cswinrt for %cswinrt_platform% %cswinrt_configuration%
msbuild cswinrt.sln /p:platform=%cswinrt_platform%;configuration=%cswinrt_configuration%;VersionNumber=%cswinrt_version_number%;VersionString=%cswinrt_version_string%;GenerateTestProjection=true
msbuild cswinrt.sln %cswinrt_build_params% /p:platform=%cswinrt_platform%;configuration=%cswinrt_configuration%;VersionNumber=%cswinrt_version_number%;VersionString=%cswinrt_version_string%;GenerateTestProjection=true

:test
rem Build/Run xUnit tests, generating xml output report for Azure Devops reporting, via XunitXml.TestLogger NuGet
Expand Down
1 change: 1 addition & 0 deletions nuget/Microsoft.Windows.CsWinRT.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<file src="$cswinrt_exe$"/>
<file src="Microsoft.Windows.CsWinRT.props" target="build"/>
<file src="Microsoft.Windows.CsWinRT.targets" target="build"/>
<file src="Microsoft.Windows.CsWinRT.Prerelease*.targets" target="build"/>
<file src="readme.txt"/>
<file src="$netstandard2_runtime$" target="lib\netstandard2.0\"/>
<file src="$net5_runtime$" target="lib\net5.0\"/>
Expand Down
2 changes: 2 additions & 0 deletions nuget/Microsoft.Windows.CsWinRT.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ Copyright (C) Microsoft Corporation. All rights reserved.
</ItemGroup>
</Target>

<Import Project="$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Prerelease.targets" Condition="Exists('$(MSBuildThisFileDirectory)Microsoft.Windows.CsWinRT.Prerelease.targets')"/>

</Project>