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

feat: Support for .NET 8 #211

Merged
merged 10 commits into from
Nov 20, 2023
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,18 @@ dotnet_diagnostic.CS0618.severity = none # Obsolete
dotnet_diagnostic.CA1305.severity = none # CultureInfo
dotnet_diagnostic.CA1837.severity = none # Use Environment.ProcessId instead of Process.GetCurrentProcess().Id


# new warnings introduced by .NET 8 targets

dotnet_diagnostic.SYSLIB1054.severity = none # Use 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
dotnet_diagnostic.SYSLIB1096.severity = none # Convert to 'GeneratedComInterface'

dotnet_diagnostic.CA1510.severity = none # Use ArgumentNullException throw helper
dotnet_diagnostic.CA1513.severity = none # Use ObjectDisposedException throw helper
dotnet_diagnostic.CA1850.severity = none # Prefer static 'HashData' method over 'ComputeHash'
dotnet_diagnostic.CA1859.severity = none # Use concrete types when possible for improved performance
dotnet_diagnostic.CA1861.severity = none # Avoid constant arrays as arguments

dotnet_diagnostic.CS1574.severity = none # XML comment has cref attribute that could not be resolved

dotnet_diagnostic.IDE0251.severity = none # Make member 'readonly'
2 changes: 1 addition & 1 deletion examples/32bit/comtestdotnet/comtestdotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;net48</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<Platforms>AnyCPU;x86</Platforms>
Expand Down
2 changes: 1 addition & 1 deletion examples/outproc/server/common/contract.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup>
<TargetFramework Condition="'$(PerformAcceptanceTest)' == '' OR '$(PerformAcceptanceTest)' != 'Runtime'">netstandard2.0</TargetFramework>
<TargetFrameworks Condition="'$(PerformAcceptanceTest)' == 'Runtime'">net6.0-windows;net48</TargetFrameworks>
<TargetFrameworks Condition="'$(PerformAcceptanceTest)' == 'Runtime'">net8.0-windows;net6.0-windows;net48</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
Expand Down
6 changes: 3 additions & 3 deletions examples/outproc/server/dotnet6/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Runtime.InteropServices;
using dSPACE.Runtime.InteropServices;
using dSPACE.Runtime.InteropServices.ComTypes;
internal class Program
internal sealed class Program
{
[DllImport("ole32.dll")]
public static extern int CoResumeClassObjects();
Expand Down Expand Up @@ -33,10 +33,10 @@ private static void Main(string[] args)

var registration = new RegistrationServices();
var cookie = registration.RegisterTypeForComClients(typeof(Server.Common.Greeter), RegistrationClassContext.LocalServer, RegistrationConnectionType.MultipleUse | RegistrationConnectionType.Suspended);

System.Console.WriteLine($"OutProc COM server running. PID:{Environment.ProcessId}");
System.Console.WriteLine($"RegisterTypeForComClients return cookie {cookie}");

var hr = CoResumeClassObjects();
if (hr < 0)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/outproc/server/dotnet6/dotnet6.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFrameworks>net8.0-windows;net6.0-windows</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.406",
"version": "8.0.100",
"rollForward": "latestPatch"
}
}
16 changes: 15 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<NoWarn>CA1416;CA1401;CA1707;CA1720;CA1711;CA2201;CA1200;CA5351;CS0618;CA1305;</NoWarn>
<NoWarn>CA1416;CA1401;CA1707;CA1720;CA1711;CA2201;CA1200;CA5351;CS0618;CA1305</NoWarn>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<RollForward>LatestMajor</RollForward>
<Authors>Mathias Nissen;Mark Lechtermann;Sebastian Osterbrink;Carsten Igel</Authors>
Expand All @@ -10,4 +10,18 @@
<AnalysisMode>Recommended</AnalysisMode>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>

<PropertyGroup>
<!--
Make sure any documentation comments which are included in code get checked for syntax during the build, but do
not report warnings for missing comments.
CS1573: Parameter 'parameter' has no matching param tag in the XML comment for 'parameter' (but other parameters do)
CS1591: Missing XML comment for publicly visible type or member 'Type_or_Member'
CS1712: Type parameter 'type_parameter' has no matching typeparam tag in the XML comment on 'type_or_member' (but other type parameters do)
-->
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<NoWarn>$(NoWarn),1573,1591,1712</NoWarn>
</PropertyGroup>


</Project>
2 changes: 1 addition & 1 deletion src/dscom.build/DefaultBuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public bool ConvertAssemblyToTypeLib(TypeLibConverterSettings settings, TaskLogg
var converter = new TypeLibConverter();

// Choose appropriate name resolver based on inputs with the Com Alias as the fallback.
var nameResolver = settings.Names != null && settings.Names.Any()
var nameResolver = settings.Names.Length != 0
? NameResolver.Create(settings.Names)
: NameResolver.Create(assembly);

Expand Down
2 changes: 1 addition & 1 deletion src/dscom.build/dscom.build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<DsComBuildTargetFrameWork>net6.0</DsComBuildTargetFrameWork>
<AssemblyName>dSPACE.Runtime.InteropServices.BuildTasks</AssemblyName>
<TargetFrameworks>$(DsComBuildTargetFrameWork);net48</TargetFrameworks>
<TargetFrameworks>net8.0;$(DsComBuildTargetFrameWork);net48</TargetFrameworks>
<PlatformTarget>x64</PlatformTarget>
<RootNamespace>dSPACE.Runtime.InteropServices.BuildTasks</RootNamespace> <MinVerVerbosity Condition="'$(Configuration)' == 'Debug'">normal</MinVerVerbosity>
<MinVerTagPrefix>v</MinVerTagPrefix>
Expand Down
39 changes: 20 additions & 19 deletions src/dscom.client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

using System.CommandLine;
using System.CommandLine.NamingConventionBinder;
using System.CommandLine.Parsing;
using System.Diagnostics;
using System.Runtime.InteropServices;

#pragma warning disable CA1861

namespace dSPACE.Runtime.InteropServices;

public static class ConsoleApp
Expand All @@ -26,38 +27,38 @@ public static int Main(string[] args)
{
var tlbexportCommand = new Command("tlbexport", "Export the assembly to the specified type library") {
new Argument<string>("Assembly", "File name of assembly to parse"),
new Option<string>(new string [] {"--out", "/out"}, description: "File name of type library to be produced"),
new Option<string[]>(new string [] {"--tlbreference", "/tlbreference"}, description: "Type library used to resolve references", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string[]>(new string [] {"--tlbrefpath", "/tlbrefpath"}, description: "Path used to resolve referenced type libraries", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string[]>(new string [] {"--asmpath", "/asmpath"}, description: "Look for assembly references here", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<bool>(new string [] {"--silent", "/silent"}, description: "Suppresses all output except for errors"),
new Option<string[]>(new string [] {"--silence", "/silence"}, description: "Suppresses output for the given warning (Can not be used with /silent)", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<bool>(new string [] {"--verbose", "/verbose"}, description: "Detailed log output"),
new Option<string[]>(new string [] {"--names", "/names"}, description: "A file in which each line specifies the capitalization of a name in the type library.", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string>(new string [] { "--overridename", "/overridename"}, description: "Overwrites the library name"),
new Option<Guid>(new string [] {"--overridetlbid", "/overridetlbid"}, description: "Overwrites the library id"),
new Option<bool?>(new string [] {"--createmissingdependenttlbs", "/createmissingdependenttlbs"}, description: "Generate missing type libraries for referenced assemblies. (default true)"),
new Option<string>(new[] {"--out", "/out"}, description: "File name of type library to be produced"),
new Option<string[]>(new[] {"--tlbreference", "/tlbreference"}, description: "Type library used to resolve references", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string[]>(new[] {"--tlbrefpath", "/tlbrefpath"}, description: "Path used to resolve referenced type libraries", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string[]>(new[] {"--asmpath", "/asmpath"}, description: "Look for assembly references here", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<bool>(new[] {"--silent", "/silent"}, description: "Suppresses all output except for errors"),
new Option<string[]>(new[] {"--silence", "/silence"}, description: "Suppresses output for the given warning (Can not be used with /silent)", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<bool>(new[] {"--verbose", "/verbose"}, description: "Detailed log output"),
new Option<string[]>(new[] {"--names", "/names"}, description: "A file in which each line specifies the capitalization of a name in the type library.", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string>(new[] { "--overridename", "/overridename"}, description: "Overwrites the library name"),
new Option<Guid>(new[] {"--overridetlbid", "/overridetlbid"}, description: "Overwrites the library id"),
new Option<bool?>(new[] {"--createmissingdependenttlbs", "/createmissingdependenttlbs"}, description: "Generate missing type libraries for referenced assemblies. (default true)"),
};

var tlbdumpCommand = new Command("tlbdump", "Dump a type library")
{
new Argument<string>("TypeLibrary", "File name of type library"),
new Option<string>(new string [] {"--out", "/out"}, description: "File name of the output"),
new Option<string[]>(new string [] {"--tlbreference", "/tlbreference"}, description: "Type library used to resolve references", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string[]>(new string [] {"--tlbrefpath", "/tlbrefpath"}, description: "Path used to resolve referenced type libraries", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string[]>(new string [] {"--filterregex", "/filterregex"}, description: "Regex to filter the output", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string>(new[] {"--out", "/out"}, description: "File name of the output"),
new Option<string[]>(new[] {"--tlbreference", "/tlbreference"}, description: "Type library used to resolve references", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string[]>(new[] {"--tlbrefpath", "/tlbrefpath"}, description: "Path used to resolve referenced type libraries", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
new Option<string[]>(new[] {"--filterregex", "/filterregex"}, description: "Regex to filter the output", getDefaultValue: () => Array.Empty<string>()) { Arity = ArgumentArity.ZeroOrMore},
};

var tlbregisterCommand = new Command("tlbregister", "Register a type library")
{
new Argument<string>("TypeLibrary", "File name of type library"),
new Option<bool>(new string [] {"--foruser", "/foruser"}, description: "Registered for use only by the calling user identity."),
new Option<bool>(new[] {"--foruser", "/foruser"}, description: "Registered for use only by the calling user identity."),
};

var tlbunregisterCommand = new Command("tlbunregister", "Unregister a type library")
{
new Argument<string>("TypeLibrary", "File name of type library"),
new Option<bool>(new string [] {"--foruser", "/foruser"}, description: "Registered for use only by the calling user identity."),
new Option<bool>(new[] {"--foruser", "/foruser"}, description: "Registered for use only by the calling user identity."),
};

var rootCommand = new RootCommand
Expand Down Expand Up @@ -162,7 +163,7 @@ private static void ConfigureTLBExportHandler(Command tlbexportCommand)

var assembly = assemblyResolver.LoadAssembly(options.Assembly);
var typeLibConverter = new TypeLibConverter();
var nameResolver = options.Names.Any() ? NameResolver.Create(options.Names) : NameResolver.Create(assembly);
var nameResolver = options.Names.Length > 0 ? NameResolver.Create(options.Names) : NameResolver.Create(assembly);
var typeLib = typeLibConverter.ConvertAssemblyToTypeLib(assembly, options, new TypeLibExporterNotifySink(options, nameResolver));

if (typeLib is ICreateTypeLib2 createTypeLib2)
Expand Down
2 changes: 1 addition & 1 deletion src/dscom.client/dscom.client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>dscom</AssemblyName>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<Platforms>AnyCPU;x86</Platforms>
<RuntimeIdentifiers Condition="'$(PackForBuildTaskTools)' == 'true'">win-x64;win-x86</RuntimeIdentifiers>
Expand Down
4 changes: 2 additions & 2 deletions src/dscom.demo/assembly1/assembly1.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;net48</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -11,7 +11,7 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisMode>Recommended</AnalysisMode>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<NoWarn>CA1416;CA1401;CA1707;CA1720;CA1711;CA2201;CA1200;CA5351;CS0618;CA1305;</NoWarn>
<NoWarn>CA1416;CA1401;CA1707;CA1720;CA1711;CA2201;CA1200;CA5351;CS0618;CA1305;CS1591</NoWarn>
<Platforms>AnyCPU;x86</Platforms>
<!-- <EnableComHosting>true</EnableComHosting> -->
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/dscom.demo/assembly2/assembly2.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;net48</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
2 changes: 1 addition & 1 deletion src/dscom.demo/assembly3/assembly3.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;net48</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
3 changes: 2 additions & 1 deletion src/dscom.demo/assembly4/assembly4.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;net48</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -13,6 +13,7 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<Platforms>AnyCPU;x86</Platforms>
<EnableComHosting>true</EnableComHosting>
<NoWarn>NU5104,CS1591</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/dscom.demo/assembly5/assembly5.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0-windows;net48</TargetFrameworks>
<TargetFrameworks>net8.0-windows;net6.0-windows;net48</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>10.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -13,6 +13,7 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<Platforms>AnyCPU;x86</Platforms>
<EnableComHosting>true</EnableComHosting>
<NoWarn>NU5104,CS1591</NoWarn>
</PropertyGroup>
<PropertyGroup>
<UseWPF>true</UseWPF>
Expand Down
2 changes: 2 additions & 0 deletions src/dscom.test/builder/DynamicAssemblyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ internal DynamicTypeBuilder WithClass(string className, string[] interfaceNames,

internal DynamicTypeBuilder WithStruct(string structName)
{
#pragma warning disable SYSLIB0050 // Type or member is obsolete
var dynamicTypeBuilder = new DynamicTypeBuilder(this, structName, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.SequentialLayout | TypeAttributes.Serializable, null, typeof(ValueType));
#pragma warning restore SYSLIB0050 // Type or member is obsolete
DynamicTypeBuilder.Add(dynamicTypeBuilder);
return dynamicTypeBuilder;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dscom.test/builder/DynamicTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public DynamicAssemblyBuilder Build(out Type? forcedTypeCreation)
{
TypeBuilder = DynamicTypeLibBuilder.ModuleBuilder.DefineType($"{Namespace}.{Name}", TypeAttributes, ParentType);

if (GenericTypeParameters.Any())
if (GenericTypeParameters.Count != 0)
{
TypeBuilder.DefineGenericParameters(GenericTypeParameters.ToArray());
}
Expand Down
2 changes: 1 addition & 1 deletion src/dscom.test/dscom.test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<TargetFrameworks>net8.0;net6.0;net48</TargetFrameworks>
<PlatformTarget>x64</PlatformTarget>
<IsPackable>false</IsPackable>
<RootNamespace>dSPACE.Runtime.InteropServices.Tests</RootNamespace>
Expand Down
Loading
Loading