我想在.net Core中构建COM对象,然后通过RegAsm注册。
我的.csproj文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.1;net4.7.2</TargetFrameworks>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<Platforms>x64</Platforms>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
我的program.cs:
using System;
using System.Runtime.InteropServices;
namespace ComExample
{
[Guid("7ce1e40f-760a-4d81-b70b-61108ed15cb4")]
[ComVisible(true)]
public interface IComExampleClass
{
IComModelClass ExampleMethod(string param1, string param2);
}
[Guid("a8436b3f-3657-4a01-a133-fd333a84cb58")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class ComExampleClass : IComExampleClass
{
public IComModelClass ExampleMethod(string param1, string param2)
{
return new ComModelClass()
{
Result = $"{param1} + {param2}"
};
}
}
[Guid("9f5aeede-ec3e-443d-8ba0-9a9f2a6b9e53")]
[ComVisible(true)]
public interface IComModelClass
{
string Result { get; set; }
}
[Guid("526c6cb5-264d-4629-a894-fff02aeb9ec1")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class ComModelClass …
Run Code Online (Sandbox Code Playgroud)