Skip to content

Integrate Shmueli's ComServer into CsWinRT #1995

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

Closed
wants to merge 18 commits into from
Closed
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
12 changes: 11 additions & 1 deletion build/AzurePipelineTemplates/CsWinRT-Build-Steps.yml
Original file line number Diff line number Diff line change
@@ -171,7 +171,7 @@ steps:
displayName: Build cswinrt.sln
inputs:
solution: $(Build.SourcesDirectory)\src\cswinrt.sln
msbuildArgs: /restore /p:CIBuildReason=CI,VersionNumber=$(VersionNumber),VersionString=$(Build.BuildNumber),AssemblyVersionNumber=$(WinRT.Runtime.AssemblyVersion),GenerateTestProjection=true,AllowedReferenceRelatedFileExtensions=".xml;.pri;.dll.config;.exe.config" /bl:$(Build.SourcesDirectory)\cswinrt.binlog
msbuildArgs: /restore /p:CIBuildReason=CI,VersionNumber=$(VersionNumber),VersionString=$(Build.BuildNumber),AssemblyVersionNumber=$(WinRT.Runtime.AssemblyVersion),ComServerHelpersAssemblyVersionNumber=$(ComServerHelpers.AssemblyVersion),GenerateTestProjection=true,AllowedReferenceRelatedFileExtensions=".xml;.pri;.dll.config;.exe.config" /bl:$(Build.SourcesDirectory)\cswinrt.binlog
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)

@@ -287,6 +287,16 @@ steps:
WinRT.Runtime.dll
WinRT.Runtime.pdb
TargetFolder: $(StagingFolder)\net8.0

- task: CopyFiles@2
displayName: Stage Net8.0
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildConfiguration'], 'release'))
inputs:
SourceFolder: $(Build.SourcesDirectory)\src\ComServerHelpers\bin\$(BuildConfiguration)\net8.0
Contents: |
ComServerHelpers.dll
ComServerHelpers.pdb
TargetFolder: $(StagingFolder)\net8.0

# Stage Net9.0
- task: CopyFiles@2
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ steps:
command: pack
searchPatternPack: nuget/Microsoft.Windows.CsWinRT.nuspec
configurationToPack: Release
buildProperties: cswinrt_nuget_version=$(NugetVersion);cswinrt_exe=$(Build.SourcesDirectory)\release_x86\native\cswinrt.exe;interop_winmd=$(Build.SourcesDirectory)\release_x86\native\WinRT.Interop.winmd;netstandard2_runtime=$(Build.SourcesDirectory)\release_x86\netstandard2.0\WinRT.Runtime.dll;net8_runtime=$(Build.SourcesDirectory)\release_x86\net8.0\WinRT.Runtime.dll;net9_runtime=$(Build.SourcesDirectory)\release_x86\net9.0\WinRT.Runtime.dll;source_generator_roslyn4080=$(Build.SourcesDirectory)\release_x86\netstandard2.0\roslyn4080\WinRT.SourceGenerator.dll;source_generator_roslyn4120=$(Build.SourcesDirectory)\release_x86\netstandard2.0\roslyn4120\WinRT.SourceGenerator.dll;winrt_shim=$(Build.SourcesDirectory)\release_x86\net8.0\WinRT.Host.Shim.dll;winrt_host_x86=$(Build.SourcesDirectory)\release_x86\native\WinRT.Host.dll;winrt_host_x64=$(Build.SourcesDirectory)\release_x64\native\WinRT.Host.dll;winrt_host_arm64=$(Build.SourcesDirectory)\release_arm64\native\WinRT.Host.dll;winrt_host_resource_x86=$(Build.SourcesDirectory)\release_x86\native\WinRT.Host.dll.mui;winrt_host_resource_x64=$(Build.SourcesDirectory)\release_x64\native\WinRT.Host.dll.mui;winrt_host_resource_arm64=$(Build.SourcesDirectory)\release_arm64\native\WinRT.Host.dll.mui;guid_patch=$(Build.SourcesDirectory)\release_x86\net8.0\IIDOptimizer\*.*
buildProperties: cswinrt_nuget_version=$(NugetVersion);cswinrt_exe=$(Build.SourcesDirectory)\release_x86\native\cswinrt.exe;interop_winmd=$(Build.SourcesDirectory)\release_x86\native\WinRT.Interop.winmd;netstandard2_runtime=$(Build.SourcesDirectory)\release_x86\netstandard2.0\WinRT.Runtime.dll;net8_runtime=$(Build.SourcesDirectory)\release_x86\net8.0\WinRT.Runtime.dll;net8_comserver_helpers=$(Build.SourcesDirectory)\release_x86\net8.0\ComServerHelpers.dll;net9_runtime=$(Build.SourcesDirectory)\release_x86\net9.0\WinRT.Runtime.dll;source_generator_roslyn4080=$(Build.SourcesDirectory)\release_x86\netstandard2.0\roslyn4080\WinRT.SourceGenerator.dll;source_generator_roslyn4120=$(Build.SourcesDirectory)\release_x86\netstandard2.0\roslyn4120\WinRT.SourceGenerator.dll;winrt_shim=$(Build.SourcesDirectory)\release_x86\net8.0\WinRT.Host.Shim.dll;winrt_host_x86=$(Build.SourcesDirectory)\release_x86\native\WinRT.Host.dll;winrt_host_x64=$(Build.SourcesDirectory)\release_x64\native\WinRT.Host.dll;winrt_host_arm64=$(Build.SourcesDirectory)\release_arm64\native\WinRT.Host.dll;winrt_host_resource_x86=$(Build.SourcesDirectory)\release_x86\native\WinRT.Host.dll.mui;winrt_host_resource_x64=$(Build.SourcesDirectory)\release_x64\native\WinRT.Host.dll.mui;winrt_host_resource_arm64=$(Build.SourcesDirectory)\release_arm64\native\WinRT.Host.dll.mui;guid_patch=$(Build.SourcesDirectory)\release_x86\net8.0\IIDOptimizer\*.*
packDestination: $(ob_outputDirectory)\packages

- task: NuGetCommand@2
2 changes: 2 additions & 0 deletions build/AzurePipelineTemplates/CsWinRT-Variables.yml
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ variables:
value: 0
- name: WinRT.Runtime.AssemblyVersion
value: '2.3.0.0'
- name: ComServerHelpers.AssemblyVersion
value: '1.0.0.0'
- name: Net5.SDK.Feed
value: 'https://dotnetcli.blob.core.windows.net/dotnet'
- name: Net8.SDK.Version
4 changes: 3 additions & 1 deletion nuget/Microsoft.Windows.CsWinRT.nuspec
Original file line number Diff line number Diff line change
@@ -34,6 +34,8 @@
<file src="readme.txt"/>
<file src="$net8_runtime$" target="lib\net8.0\"/>
<file src="$net9_runtime$" target="lib\net9.0\"/>
<file src="$net8_comserver_helpers$" target="lib\net8.0\"/>
<file src="$net8_comserver_helpers$" target="lib\net9.0\"/>
<file src="$source_generator_roslyn4080$" target="analyzers\dotnet\cs\roslyn4.8"/>
<file src="$source_generator_roslyn4120$" target="analyzers\dotnet\cs\roslyn4.12"/>
<file src="$winrt_host_x64$" target ="hosting\x64\native"/>
@@ -72,7 +74,7 @@
<file src="..\src\WinRT.Runtime\Projections\*netstandard2.0*.cs" target="embedded\netstandard2.0\" />

<file src="..\src\WinRT.Runtime\Configuration\*.cs" exclude="..\src\WinRT.Runtime\Configuration\*.net*.cs" target="embedded\any\" />

<file src="sources\StubExe.c" target="build\sources"/>

<file src="$guid_patch$" target="build\tools\IIDOptimizer"/>
37 changes: 37 additions & 0 deletions src/ComServerHelpers/BaseActivationFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Runtime.Versioning;

namespace ComServerHelpers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really think about what actual namespace names to use. And type names.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your suggestion?


/// <summary>
/// Base for a WinRT Activation Factory for a .NET type.
/// </summary>
[SupportedOSPlatform("windows8.0")]
public abstract class BaseActivationFactory
{
/// <inheritdoc/>
public abstract object ActivateInstance();

/// <summary>
/// Gets the Activatable Class ID.
/// </summary>
public abstract string ActivatableClassId { get; }

/// <summary>
/// Occurs when a new instance is created.
/// </summary>
public event EventHandler<InstanceCreatedEventArgs>? InstanceCreated;

/// <summary>
/// Raises the <see cref="InstanceCreated"/> event.
/// </summary>
/// <param name="instance">The created instance.</param>
/// <event cref="InstanceCreated"/>
internal void OnInstanceCreated(object instance)
{
InstanceCreated?.Invoke(this, new InstanceCreatedEventArgs(instance));
}
}
55 changes: 55 additions & 0 deletions src/ComServerHelpers/BaseClassFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Runtime.Versioning;

namespace ComServerHelpers;

/// <summary>
/// Base for a COM class factory for a .NET type.
/// </summary>
/// <remarks>Does not support aggregation. Will always return <c>CLASS_E_NOAGGREGATION</c> if requested.</remarks>
[SupportedOSPlatform("windows6.0.6000")]
public abstract class BaseClassFactory
{
// Properties (special values)
/// <summary>
/// Gets the <c>CLSID</c>.
/// </summary>
protected internal abstract Guid Clsid
{
get;
}

/// <summary>
/// Gets the <c>IID</c>.
/// </summary>
protected internal abstract Guid Iid
{
get;
}

// Events
/// <summary>
/// Occurs when a new instance is created.
/// </summary>
public event EventHandler<InstanceCreatedEventArgs>? InstanceCreated;

// Other members (methods)
/// <summary>
/// Creates an instance of the object.
/// </summary>
/// <returns>An instance of the object.</returns>
protected internal abstract object CreateInstance();

/// <summary>
/// Raises the <see cref="InstanceCreated"/> event.
/// </summary>
/// <param name="instance">The created instance.</param>
/// <event cref="InstanceCreated"/>
internal void OnInstanceCreated(object instance)
{
InstanceCreated?.Invoke(this, new InstanceCreatedEventArgs(instance));
}
}
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.