diff options
author | Lluis Sanchez <llsan@microsoft.com> | 2021-08-24 10:08:35 +0300 |
---|---|---|
committer | Lluis Sanchez <llsan@microsoft.com> | 2021-08-24 10:08:35 +0300 |
commit | a6885a748fbdb95a904572b93f9bcceeb86bcf88 (patch) | |
tree | 848a6d94910ba00d0f52bd638d179d371b5ec0c2 | |
parent | 60ac8e99c51e43a58a4dc124b9680fb73c2f974b (diff) |
Allow building with .NET 6
Ported projects to sdk-style and added ifdefs to allow compiling
with .NET 6
11 files changed, 90 insertions, 35 deletions
diff --git a/ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj b/ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj index 0d12aaaf..9a2fb47f 100644 --- a/ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj +++ b/ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj @@ -1,5 +1,5 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> +<?xml version="1.0" encoding="utf-8"?> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <ProjectGuid>{53DCA265-3C3C-42F9-B647-F72BA678122B}</ProjectGuid> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> @@ -23,7 +23,10 @@ <NoWin32Manifest>False</NoWin32Manifest> <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> <DocumentationFile>$(IntermediateOutputPath)ICSharpCode.NRefactory.CSharp.xml</DocumentationFile> - </PropertyGroup> + <GenerateAssemblyInfo>false</GenerateAssemblyInfo> + <EnableDefaultCompileItems>False</EnableDefaultCompileItems> + <EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems> + <TargetFramework>net472</TargetFramework> </PropertyGroup> <PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <RegisterForComInterop>False</RegisterForComInterop> @@ -396,7 +399,6 @@ <Name>ICSharpCode.NRefactory</Name> </ProjectReference> </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup /> <ProjectExtensions> <MonoDevelop> diff --git a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs index da1f4d6e..298c303c 100644 --- a/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs +++ b/ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs @@ -16,6 +16,8 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#if !NET6_0 + using System; using System.CodeDom; using System.Collections.Generic; @@ -1427,3 +1429,5 @@ namespace ICSharpCode.NRefactory.CSharp } } } + +#endif
\ No newline at end of file diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs index 0850e720..75281ba5 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs @@ -462,7 +462,11 @@ namespace ICSharpCode.NRefactory.MonoCSharp // but returned ISymbolWriter does not have all what we need therefore some // adaptor will be needed for now we alwayas emit MDB format when generating // debug info +#if NET6_0 + return Builder.DefineDynamicModule(module_name); +#else return Builder.DefineDynamicModule (module_name, module_name, false); +#endif } public virtual void Emit () @@ -787,11 +791,13 @@ namespace ICSharpCode.NRefactory.MonoCSharp // // Add Win32 resources // +#if !NET6_0 if (Compiler.Settings.Win32ResourceFile != null) { Builder.DefineUnmanagedResource (Compiler.Settings.Win32ResourceFile); } else { Builder.DefineVersionInfoResource (vi_product, vi_product_version, vi_company, vi_copyright, vi_trademark); } +#endif if (Compiler.Settings.Win32IconFile != null) { builder_extra.DefineWin32IconResource (Compiler.Settings.Win32IconFile); @@ -819,9 +825,13 @@ namespace ICSharpCode.NRefactory.MonoCSharp stream = new MemoryStream (File.ReadAllBytes (res.FileName)); } +#if !NET6_0 module.Builder.DefineManifestResource (res.Name, stream, res.Attributes); +#endif } else { +#if !NET6_0 Builder.AddResourceFile (res.Name, Path.GetFileName (res.FileName), res.Attributes); +#endif } } } @@ -871,7 +881,11 @@ namespace ICSharpCode.NRefactory.MonoCSharp if (Compiler.Settings.Target == Target.Module) { SaveModule (pekind, machine); } else { +#if NET6_0 + throw new NotSupportedException(); +#else Builder.Save (module.Builder.ScopeName, pekind, machine); +#endif } } catch (Exception e) { Report.Error (16, "Could not write to file `" + name + "', cause: " + e.Message); @@ -964,7 +978,9 @@ namespace ICSharpCode.NRefactory.MonoCSharp return; } +#if !NET6_0 Builder.SetEntryPoint (entry_point.MethodBuilder, file_kind); +#endif } void Error_ObsoleteSecurityAttribute (Attribute a, string option) @@ -1043,14 +1059,14 @@ namespace ICSharpCode.NRefactory.MonoCSharp public string FileName { get; private set; } public bool IsEmbeded { get; set; } - #region IEquatable<AssemblyResource> Members +#region IEquatable<AssemblyResource> Members public bool Equals (AssemblyResource other) { return Name == other.Name; } - #endregion +#endregion } // @@ -1258,4 +1274,16 @@ namespace ICSharpCode.NRefactory.MonoCSharp compiler.TimeReporter.Stop (TimeReporter.TimerType.ReferencesLoading); } } -} + +#if NET6_0 + + enum PEFileKinds + { + Dll = 1, + ConsoleApplication = 2, + WindowApplication = 3 + } + +#endif + + } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs index d14c5953..d43f3510 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs @@ -2766,7 +2766,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp foreach (var de in declarative_security) { #if STATIC TypeBuilder.__AddDeclarativeSecurity (de); -#else +#elif !NET6_0 TypeBuilder.AddDeclarativeSecurity (de.Key, de.Value); #endif } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs index dd726110..1d1e7b4c 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs @@ -357,8 +357,10 @@ namespace ICSharpCode.NRefactory.MonoCSharp if (!ctx.BuiltinTypes.CheckDefinitions (module)) return false; +#if !NET6_0 if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save)) return false; +#endif module.CreateContainer (); diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs index 17f29cc1..81a237e5 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs @@ -686,7 +686,11 @@ namespace ICSharpCode.NRefactory.MonoCSharp AssemblyBuilderAccess access; if (Environment.GetEnvironmentVariable ("SAVE") != null) { +#if NET6_0 + access = AssemblyBuilderAccess.Run; +#else access = AssemblyBuilderAccess.RunAndSave; +#endif assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name); assembly.Importer = importer; } else { @@ -786,8 +790,10 @@ namespace ICSharpCode.NRefactory.MonoCSharp if (host != null) host.CloseContainer (); +#if !NET6_0 if (access == AssemblyBuilderAccess.RunAndSave) assembly.Save (); +#endif if (host == null) return null; diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs index 0ce37f6b..baf44242 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs @@ -711,7 +711,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp { foreach (var de in declarative_security) { #if STATIC MethodBuilder.__AddDeclarativeSecurity (de); -#else +#elif !NET6_0 MethodBuilder.AddDeclarativeSecurity (de.Key, de.Value); #endif } @@ -1801,7 +1801,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp { foreach (var de in declarative_security) { #if STATIC ConstructorBuilder.__AddDeclarativeSecurity (de); -#else +#elif !NET6_0 ConstructorBuilder.AddDeclarativeSecurity (de.Key, de.Value); #endif } @@ -1861,6 +1861,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp { if (debug_builder == null) return; +#if !NET6_0 var token = ConstructorBuilder.GetToken (); int t = token.Token; #if STATIC @@ -1869,9 +1870,10 @@ namespace ICSharpCode.NRefactory.MonoCSharp { #endif debug_builder.DefineMethod (file, t); +#endif } - #region IMethodData Members +#region IMethodData Members public MemberName MethodName { get { @@ -1890,7 +1892,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp { throw new NotImplementedException (); } - #endregion +#endregion } /// <summary> @@ -2191,6 +2193,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp { if (debug_builder == null) return; +#if !NET6_0 var token = builder.GetToken (); int t = token.Token; #if STATIC @@ -2199,6 +2202,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp { #endif debug_builder.DefineMethod (file, t); +#endif } } @@ -2337,7 +2341,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp { SetMemberName (SetupName (prefix, member, Location)); } - #region IMethodData Members +#region IMethodData Members public ToplevelBlock Block { get { @@ -2387,7 +2391,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp { public abstract ParametersCompiled ParameterInfo { get ; } public abstract TypeSpec ReturnType { get; } - #endregion +#endregion public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa) { @@ -2454,7 +2458,7 @@ namespace ICSharpCode.NRefactory.MonoCSharp { foreach (var de in declarative_security) { #if STATIC method_data.MethodBuilder.__AddDeclarativeSecurity (de); -#else +#elif !NET6_0 method_data.MethodBuilder.AddDeclarativeSecurity (de.Key, de.Value); #endif } diff --git a/ICSharpCode.NRefactory.CSharp/Parser/mcs/reflection.cs b/ICSharpCode.NRefactory.CSharp/Parser/mcs/reflection.cs index 936818f0..47d75c6a 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/mcs/reflection.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/mcs/reflection.cs @@ -209,17 +209,21 @@ namespace ICSharpCode.NRefactory.MonoCSharp public override ModuleBuilder CreateModuleBuilder () { if (file_name == null) +#if NET6_0 + return Builder.DefineDynamicModule(Name); +#else return Builder.DefineDynamicModule (Name, false); +#endif return base.CreateModuleBuilder (); } #endif - // - // Initializes the code generator - // + // + // Initializes the code generator + // public bool Create (AppDomain domain, AssemblyBuilderAccess access) { -#if STATIC || FULL_AOT_RUNTIME +#if STATIC || FULL_AOT_RUNTIME || NETCOREAPP throw new NotSupportedException (); #else ResolveAssemblySecurityAttributes (); @@ -261,10 +265,12 @@ namespace ICSharpCode.NRefactory.MonoCSharp base.SaveModule (pekind, machine); } +#if !NETCOREAPP Builder.Save (file_name, pekind, machine); +#endif } #endif - } + } // // Extension to System.Reflection.Emit.AssemblyBuilder to have fully compatible diff --git a/ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj b/ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj index bb6dcf32..8b4bc139 100644 --- a/ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj +++ b/ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> @@ -18,7 +18,12 @@ <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> <DocumentationFile>$(IntermediateOutputPath)ICSharpCode.NRefactory.Cecil.xml</DocumentationFile> <NoWarn>1591</NoWarn> - </PropertyGroup> + <GenerateAssemblyInfo>false</GenerateAssemblyInfo> + <EnableDefaultCompileItems>False</EnableDefaultCompileItems> + <EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems> + <TargetFramework>net472</TargetFramework> + <Configurations>Debug;Release;net_4_5_Debug;net_4_5_Release</Configurations> +</PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> <DebugType>Full</DebugType> @@ -27,7 +32,6 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <ConsolePause>false</ConsolePause> - <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <DebugType>PdbOnly</DebugType> @@ -36,7 +40,6 @@ <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> <ConsolePause>false</ConsolePause> - <TargetFrameworkVersion>v4.0</TargetFrameworkVersion> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -99,11 +102,8 @@ <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="CecilLoader.cs" /> </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <ItemGroup> <ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> - <Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> - <Name>ICSharpCode.NRefactory</Name> </ProjectReference> </ItemGroup> </Project> diff --git a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj index c24afdd2..0476896e 100644 --- a/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj +++ b/ICSharpCode.NRefactory/ICSharpCode.NRefactory.csproj @@ -1,5 +1,5 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> +<?xml version="1.0" encoding="utf-8"?> +<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <ProjectGuid>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</ProjectGuid> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> @@ -8,16 +8,12 @@ <RootNamespace>ICSharpCode.NRefactory</RootNamespace> <AssemblyName>ICSharpCode.NRefactory</AssemblyName> <AppDesignerFolder>Properties</AppDesignerFolder> - <ProductVersion>10.0.0</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> <AllowUnsafeBlocks>False</AllowUnsafeBlocks> - <NoStdLib>False</NoStdLib> <TreatWarningsAsErrors>False</TreatWarningsAsErrors> <RunCodeAnalysis>False</RunCodeAnalysis> <CodeAnalysisRules>-Microsoft.Design#CA1000;-Microsoft.Design#CA1004;-Microsoft.Design#CA1005;-Microsoft.Design#CA1006;-Microsoft.Design#CA1026;-Microsoft.Design#CA1033;-Microsoft.Design#CA1051;-Microsoft.Design#CA1063;-Microsoft.Naming#CA1702;-Microsoft.Naming#CA1704;-Microsoft.Naming#CA1710;-Microsoft.Naming#CA1716;-Microsoft.Naming#CA1720;-Microsoft.Performance#CA1800;-Microsoft.Security#CA2104</CodeAnalysisRules> <SignAssembly>True</SignAssembly> <AssemblyOriginatorKeyFile>..\ICSharpCode.NRefactory.snk</AssemblyOriginatorKeyFile> - <DelaySign>False</DelaySign> <AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode> <WarningLevel>4</WarningLevel> <NoWarn>1591</NoWarn> @@ -25,6 +21,11 @@ <NoWin32Manifest>False</NoWin32Manifest> <IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath> <DocumentationFile>$(IntermediateOutputPath)ICSharpCode.NRefactory.xml</DocumentationFile> + <GenerateAssemblyInfo>false</GenerateAssemblyInfo> + <EnableDefaultCompileItems>False</EnableDefaultCompileItems> + <EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems> + <TargetFramework>net472</TargetFramework> + <Configurations>Debug;Release;net_4_5_Debug;net_4_5_Release</Configurations> </PropertyGroup> <PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> @@ -309,5 +310,4 @@ <Link>Documentation\XML Documentation.html</Link> </None> </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/ICSharpCode.NRefactory/TypeSystem/Implementation/UnresolvedSecurityDeclarationBlob.cs b/ICSharpCode.NRefactory/TypeSystem/Implementation/UnresolvedSecurityDeclarationBlob.cs index 0b4bc2cb..923d7ba7 100644 --- a/ICSharpCode.NRefactory/TypeSystem/Implementation/UnresolvedSecurityDeclarationBlob.cs +++ b/ICSharpCode.NRefactory/TypeSystem/Implementation/UnresolvedSecurityDeclarationBlob.cs @@ -27,8 +27,9 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation public sealed class UnresolvedSecurityDeclarationBlob { static readonly ITypeReference securityActionTypeReference = typeof(System.Security.Permissions.SecurityAction).ToTypeReference(); +#if !NET6_0 static readonly ITypeReference permissionSetAttributeTypeReference = typeof(System.Security.Permissions.PermissionSetAttribute).ToTypeReference(); - +#endif readonly IConstantValue securityAction; readonly byte[] blob; readonly IList<IUnresolvedAttribute> unresolvedAttributes = new List<IUnresolvedAttribute>(); @@ -45,6 +46,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation unresolvedAttributes.Add(new UnresolvedSecurityAttribute(this, (int)i)); } } else { +#if !NET6_0 // for backward compatibility with .NET 1.0: XML-encoded attribute var attr = new DefaultUnresolvedAttribute(permissionSetAttributeTypeReference); attr.ConstructorParameterTypes.Add(securityActionTypeReference); @@ -52,6 +54,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation string xml = System.Text.Encoding.Unicode.GetString(blob); attr.AddNamedPropertyArgument("XML", new SimpleConstantValue(KnownTypeReference.String, xml)); unresolvedAttributes.Add(attr); +#endif } } |