Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit 074fabe

Browse files
Merge pull request #3 from xamarin/net6
Allow building with .NET 6
2 parents 495405a + fb5f153 commit 074fabe

File tree

12 files changed

+765
-51
lines changed

12 files changed

+765
-51
lines changed

Diff for: ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

+396-17
Large diffs are not rendered by default.

Diff for: ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
1717
// DEALINGS IN THE SOFTWARE.
1818

19+
#if !NET6_0
20+
1921
using System;
2022
using System.CodeDom;
2123
using System.Collections.Generic;
@@ -1427,3 +1429,5 @@ CodeObject IAstVisitor<CodeObject>.VisitDocumentationReference(DocumentationRefe
14271429
}
14281430
}
14291431
}
1432+
1433+
#endif

Diff for: ICSharpCode.NRefactory.CSharp/Parser/mcs/assembly.cs

+31-3
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,11 @@ public virtual ModuleBuilder CreateModuleBuilder ()
462462
// but returned ISymbolWriter does not have all what we need therefore some
463463
// adaptor will be needed for now we alwayas emit MDB format when generating
464464
// debug info
465+
#if NET6_0
466+
return Builder.DefineDynamicModule(module_name);
467+
#else
465468
return Builder.DefineDynamicModule (module_name, module_name, false);
469+
#endif
466470
}
467471

468472
public virtual void Emit ()
@@ -787,11 +791,13 @@ public void EmbedResources ()
787791
//
788792
// Add Win32 resources
789793
//
794+
#if !NET6_0
790795
if (Compiler.Settings.Win32ResourceFile != null) {
791796
Builder.DefineUnmanagedResource (Compiler.Settings.Win32ResourceFile);
792797
} else {
793798
Builder.DefineVersionInfoResource (vi_product, vi_product_version, vi_company, vi_copyright, vi_trademark);
794799
}
800+
#endif
795801

796802
if (Compiler.Settings.Win32IconFile != null) {
797803
builder_extra.DefineWin32IconResource (Compiler.Settings.Win32IconFile);
@@ -819,9 +825,13 @@ public void EmbedResources ()
819825
stream = new MemoryStream (File.ReadAllBytes (res.FileName));
820826
}
821827

828+
#if !NET6_0
822829
module.Builder.DefineManifestResource (res.Name, stream, res.Attributes);
830+
#endif
823831
} else {
832+
#if !NET6_0
824833
Builder.AddResourceFile (res.Name, Path.GetFileName (res.FileName), res.Attributes);
834+
#endif
825835
}
826836
}
827837
}
@@ -871,7 +881,11 @@ public void Save ()
871881
if (Compiler.Settings.Target == Target.Module) {
872882
SaveModule (pekind, machine);
873883
} else {
884+
#if NET6_0
885+
throw new NotSupportedException();
886+
#else
874887
Builder.Save (module.Builder.ScopeName, pekind, machine);
888+
#endif
875889
}
876890
} catch (Exception e) {
877891
Report.Error (16, "Could not write to file `" + name + "', cause: " + e.Message);
@@ -964,7 +978,9 @@ void SetEntryPoint ()
964978
return;
965979
}
966980

981+
#if !NET6_0
967982
Builder.SetEntryPoint (entry_point.MethodBuilder, file_kind);
983+
#endif
968984
}
969985

970986
void Error_ObsoleteSecurityAttribute (Attribute a, string option)
@@ -1043,14 +1059,14 @@ public AssemblyResource (string fileName, string name, bool isPrivate)
10431059
public string FileName { get; private set; }
10441060
public bool IsEmbeded { get; set; }
10451061

1046-
#region IEquatable<AssemblyResource> Members
1062+
#region IEquatable<AssemblyResource> Members
10471063

10481064
public bool Equals (AssemblyResource other)
10491065
{
10501066
return Name == other.Name;
10511067
}
10521068

1053-
#endregion
1069+
#endregion
10541070
}
10551071

10561072
//
@@ -1258,4 +1274,16 @@ protected void LoadReferencesCore (ModuleContainer module, out T corlib_assembly
12581274
compiler.TimeReporter.Stop (TimeReporter.TimerType.ReferencesLoading);
12591275
}
12601276
}
1261-
}
1277+
1278+
#if NET6_0
1279+
1280+
enum PEFileKinds
1281+
{
1282+
Dll = 1,
1283+
ConsoleApplication = 2,
1284+
WindowApplication = 3
1285+
}
1286+
1287+
#endif
1288+
1289+
}

Diff for: ICSharpCode.NRefactory.CSharp/Parser/mcs/class.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2766,7 +2766,7 @@ public override void Emit ()
27662766
foreach (var de in declarative_security) {
27672767
#if STATIC
27682768
TypeBuilder.__AddDeclarativeSecurity (de);
2769-
#else
2769+
#elif !NET6_0
27702770
TypeBuilder.AddDeclarativeSecurity (de.Key, de.Value);
27712771
#endif
27722772
}

Diff for: ICSharpCode.NRefactory.CSharp/Parser/mcs/driver.cs

+2
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,10 @@ public bool Compile ()
357357
if (!ctx.BuiltinTypes.CheckDefinitions (module))
358358
return false;
359359

360+
#if !NET6_0
360361
if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
361362
return false;
363+
#endif
362364

363365
module.CreateContainer ();
364366

Diff for: ICSharpCode.NRefactory.CSharp/Parser/mcs/eval.cs

+6
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,11 @@ CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
686686
AssemblyBuilderAccess access;
687687

688688
if (Environment.GetEnvironmentVariable ("SAVE") != null) {
689+
#if NET6_0
690+
access = AssemblyBuilderAccess.Run;
691+
#else
689692
access = AssemblyBuilderAccess.RunAndSave;
693+
#endif
690694
assembly = new AssemblyDefinitionDynamic (module, current_debug_name, current_debug_name);
691695
assembly.Importer = importer;
692696
} else {
@@ -786,8 +790,10 @@ CompiledMethod CompileBlock (Class host, Undo undo, Report Report)
786790
if (host != null)
787791
host.CloseContainer ();
788792

793+
#if !NET6_0
789794
if (access == AssemblyBuilderAccess.RunAndSave)
790795
assembly.Save ();
796+
#endif
791797

792798
if (host == null)
793799
return null;

Diff for: ICSharpCode.NRefactory.CSharp/Parser/mcs/method.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ public override void Emit ()
711711
foreach (var de in declarative_security) {
712712
#if STATIC
713713
MethodBuilder.__AddDeclarativeSecurity (de);
714-
#else
714+
#elif !NET6_0
715715
MethodBuilder.AddDeclarativeSecurity (de.Key, de.Value);
716716
#endif
717717
}
@@ -1801,7 +1801,7 @@ public override void Emit ()
18011801
foreach (var de in declarative_security) {
18021802
#if STATIC
18031803
ConstructorBuilder.__AddDeclarativeSecurity (de);
1804-
#else
1804+
#elif !NET6_0
18051805
ConstructorBuilder.AddDeclarativeSecurity (de.Key, de.Value);
18061806
#endif
18071807
}
@@ -1861,6 +1861,7 @@ public override void WriteDebugSymbol (MonoSymbolFile file)
18611861
if (debug_builder == null)
18621862
return;
18631863

1864+
#if !NET6_0
18641865
var token = ConstructorBuilder.GetToken ();
18651866
int t = token.Token;
18661867
#if STATIC
@@ -1869,9 +1870,10 @@ public override void WriteDebugSymbol (MonoSymbolFile file)
18691870
#endif
18701871

18711872
debug_builder.DefineMethod (file, t);
1873+
#endif
18721874
}
18731875

1874-
#region IMethodData Members
1876+
#region IMethodData Members
18751877

18761878
public MemberName MethodName {
18771879
get {
@@ -1890,7 +1892,7 @@ EmitContext IMethodData.CreateEmitContext (ILGenerator ig, SourceMethodBuilder s
18901892
throw new NotImplementedException ();
18911893
}
18921894

1893-
#endregion
1895+
#endregion
18941896
}
18951897

18961898
/// <summary>
@@ -2191,6 +2193,7 @@ public void WriteDebugSymbol (MonoSymbolFile file)
21912193
if (debug_builder == null)
21922194
return;
21932195

2196+
#if !NET6_0
21942197
var token = builder.GetToken ();
21952198
int t = token.Token;
21962199
#if STATIC
@@ -2199,6 +2202,7 @@ public void WriteDebugSymbol (MonoSymbolFile file)
21992202
#endif
22002203

22012204
debug_builder.DefineMethod (file, t);
2205+
#endif
22022206
}
22032207
}
22042208

@@ -2337,7 +2341,7 @@ public void UpdateName (InterfaceMemberBase member)
23372341
SetMemberName (SetupName (prefix, member, Location));
23382342
}
23392343

2340-
#region IMethodData Members
2344+
#region IMethodData Members
23412345

23422346
public ToplevelBlock Block {
23432347
get {
@@ -2387,7 +2391,7 @@ MethodBase IMethodDefinition.Metadata {
23872391
public abstract ParametersCompiled ParameterInfo { get ; }
23882392
public abstract TypeSpec ReturnType { get; }
23892393

2390-
#endregion
2394+
#endregion
23912395

23922396
public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
23932397
{
@@ -2454,7 +2458,7 @@ public virtual void Emit (TypeDefinition parent)
24542458
foreach (var de in declarative_security) {
24552459
#if STATIC
24562460
method_data.MethodBuilder.__AddDeclarativeSecurity (de);
2457-
#else
2461+
#elif !NET6_0
24582462
method_data.MethodBuilder.AddDeclarativeSecurity (de.Key, de.Value);
24592463
#endif
24602464
}

Diff for: ICSharpCode.NRefactory.CSharp/Parser/mcs/reflection.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,21 @@ public Module IncludeModule (string moduleFile)
209209
public override ModuleBuilder CreateModuleBuilder ()
210210
{
211211
if (file_name == null)
212+
#if NET6_0
213+
return Builder.DefineDynamicModule(Name);
214+
#else
212215
return Builder.DefineDynamicModule (Name, false);
216+
#endif
213217

214218
return base.CreateModuleBuilder ();
215219
}
216220
#endif
217-
//
218-
// Initializes the code generator
219-
//
221+
//
222+
// Initializes the code generator
223+
//
220224
public bool Create (AppDomain domain, AssemblyBuilderAccess access)
221225
{
222-
#if STATIC || FULL_AOT_RUNTIME
226+
#if STATIC || FULL_AOT_RUNTIME || NETCOREAPP
223227
throw new NotSupportedException ();
224228
#else
225229
ResolveAssemblySecurityAttributes ();
@@ -261,10 +265,12 @@ protected override void SaveModule (PortableExecutableKinds pekind, ImageFileMac
261265
base.SaveModule (pekind, machine);
262266
}
263267

268+
#if !NETCOREAPP
264269
Builder.Save (file_name, pekind, machine);
270+
#endif
265271
}
266272
#endif
267-
}
273+
}
268274

269275
//
270276
// Extension to System.Reflection.Emit.AssemblyBuilder to have fully compatible

Diff for: ICSharpCode.NRefactory.Cecil/CecilLoader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public IUnresolvedAssembly LoadModule(ModuleDefinition moduleDefinition)
182182
moduleAttributes = interningProvider.InternList(moduleAttributes);
183183

184184
this.currentAssembly = new CecilUnresolvedAssembly(assemblyDefinition != null ? assemblyDefinition.Name.FullName : moduleDefinition.Name, this.DocumentationProvider);
185-
currentAssembly.Location = moduleDefinition.FullyQualifiedName;
185+
currentAssembly.Location = moduleDefinition.FileName;
186186
currentAssembly.AssemblyAttributes.AddRange(assemblyAttributes);
187187
currentAssembly.ModuleAttributes.AddRange(assemblyAttributes);
188188

Diff for: ICSharpCode.NRefactory.Cecil/ICSharpCode.NRefactory.Cecil.csproj

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -18,7 +18,12 @@
1818
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
1919
<DocumentationFile>$(IntermediateOutputPath)ICSharpCode.NRefactory.Cecil.xml</DocumentationFile>
2020
<NoWarn>1591</NoWarn>
21-
</PropertyGroup>
21+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
22+
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
23+
<EnableDefaultEmbeddedResourceItems>False</EnableDefaultEmbeddedResourceItems>
24+
<TargetFramework>net472</TargetFramework>
25+
<Configurations>Debug;Release;net_4_5_Debug;net_4_5_Release</Configurations>
26+
</PropertyGroup>
2227
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2328
<DebugSymbols>true</DebugSymbols>
2429
<DebugType>Full</DebugType>
@@ -27,7 +32,6 @@
2732
<ErrorReport>prompt</ErrorReport>
2833
<WarningLevel>4</WarningLevel>
2934
<ConsolePause>false</ConsolePause>
30-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
3135
</PropertyGroup>
3236
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3337
<DebugType>PdbOnly</DebugType>
@@ -36,7 +40,6 @@
3640
<ErrorReport>prompt</ErrorReport>
3741
<WarningLevel>4</WarningLevel>
3842
<ConsolePause>false</ConsolePause>
39-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
4043
</PropertyGroup>
4144
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'net_4_5_Debug|AnyCPU' ">
4245
<DebugSymbols>true</DebugSymbols>
@@ -99,11 +102,8 @@
99102
<Compile Include="Properties\AssemblyInfo.cs" />
100103
<Compile Include="CecilLoader.cs" />
101104
</ItemGroup>
102-
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
103105
<ItemGroup>
104106
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">
105-
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project>
106-
<Name>ICSharpCode.NRefactory</Name>
107107
</ProjectReference>
108108
</ItemGroup>
109109
</Project>

0 commit comments

Comments
 (0)