.NET Standard support - #5
Conversation
Incomplete System.Reflection.Emit: https://github.com/dotnet/coreclr/issues/10199
Also contains some small hacks around Java code depending on .NET-specific code, not available in .NET Standard or extensions
halex2005
left a comment
There was a problem hiding this comment.
Thanks for great work!
I've taken a look and reviewed some parts of PR.
I hope someone will review this PR too.
| @@ -1,159 +1,78 @@ | |||
| <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> | |||
| <Project Sdk="Microsoft.NET.Sdk"> | |||
There was a problem hiding this comment.
Now when you use new csproj format, I suggest to use PackageReference instead of direct storing nuget packages folder in git.
| <Name>ICSharpCode.SharpZipLib</Name> | ||
| <HintPath>bin\ICSharpCode.SharpZipLib.dll</HintPath> | ||
| </Reference> | ||
| <Reference Include="IKVM.Runtime, Version=0.46.0.5, Culture=neutral, PublicKeyToken=null"> |
There was a problem hiding this comment.
I think that project reference will be better than assembly reference with explicit version specified
| Console.Error.WriteLine(" -nostdlib Do not reference standard libraries"); | ||
| Console.Error.WriteLine(" -lib:<dir> Additional directories to search for references"); | ||
| Console.Error.WriteLine(" -noautoserialization Disable automatic .NET serialization support"); | ||
| Console.Error.WriteLine(" -netstandard Generate .NET Standard libraries"); |
There was a problem hiding this comment.
May be useful to mark this line with (default) . Also, here you use two tabs instead of spaces, it may looks ugly in console.
| if (peer.assembly.Equals(reference, StringComparison.InvariantCultureIgnoreCase)) | ||
| { | ||
| ArrayAppend(ref target.peerReferences, peer.assembly); | ||
| goto next_reference; |
There was a problem hiding this comment.
You may remove ugly goto and get code more readable if you rewrite code with some LINQ.
There was a problem hiding this comment.
If I understood your code right, consider something like:
var peerAssemblies = targets
.Where(peer => target.unresolvedNetStandardReferences.Contains(peer.assembly, StringComparison.InvariantCultureIgnoreCase))
.ToArray();
foreach (var reference in peerAssemblies)
{
ArrayAppend(ref target.peerReferences, peer.assembly);
}
foreach (var reference in target.unresolvedNetStandardReferences.Where(reference => targets.All(peer => !peer.assembly.Equals(reference, StringComparison.InvariantCultureIgnoreCase))))
{
int rc = resolver.ResolveReference(cache, ref target.references, reference, true);
if (rc != 0)
{
return rc;
}
}| int rc = resolver.ResolveReference(cache, ref target.references, reference, true); | ||
| if (rc != 0) | ||
| { | ||
| return rc; |
There was a problem hiding this comment.
I don't like this return statement. Not all peer assemblies could be added to target.peerReferences sometime.
| <property name="pathsep" value=";" /> | ||
| </if> | ||
|
|
||
| <target name="all.netstandard"> |
| # jeroen@frijters.net | ||
| # | ||
|
|
||
| assembly.class |
There was a problem hiding this comment.
Is this file supposed to be included in git history?
| @@ -0,0 +1,13 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <packages> | |||
| <package id="Microsoft.Win32.Registry" version="4.5.0" targetFramework="net461" /> | |||
There was a problem hiding this comment.
I suggest to remove this file and packages folder due to new csproj format is used. We could use PackageReference in csproj instead.
| internal void DefineSymbolDocument(ModuleBuilder module, string url, Guid language, Guid languageVendor, Guid documentType) | ||
| { | ||
| #if NETSTANDARD | ||
| throw new PlatformNotSupportedException(); |
There was a problem hiding this comment.
So many potential runtime errors. Could we workaround this sometime?
| #if NETSTANDARD | ||
| throw new PlatformNotSupportedException(); | ||
| #else | ||
| symbols = module.DefineDocument(url, language, languageVendor, documentType); |
There was a problem hiding this comment.
May be targeting .net standard 2.1 brings module builder API https://docs.microsoft.com/ru-ru/dotnet/api/system.reflection.emit.modulebuilder
|
Curious why this excellent work was based on such an old branch as opposed to, say, |
|
@zgramana Unfortunately we're using this version because trying to use it with Java 8 brings breaking changes (e.g., default implemented method) which we cannot afford right now. However, I might be able to give it a try to apply the changes on a newer branch, but can't promise anything as it's not primary focus. |
|
Interesting. I’ve used this PR as a guide to add support to master. I haven’t completed all of it yet, as I’m torn between replacing I don’t think that I fully understood your comment about Java 8 breaking changes and “default implemented method”. Could you explain that in a little detail? |
|
We have many dlls compiled from java6-7 on different projects and need them to be compatible together at runtime (dynamic loading). Switching only one of them to java8 means we need to have two different ikvm version at runtime, but also that we need a version of every dlls for both versions, but also that objects cannot be shared between both runtimes. This was caused indirectly by the way default interfaces methods are handled, which makes interfaces runtime differ, so a class implementing an interface cannot be shared. |
Requires first and foremost adding the .NET Standard framework in the NAnt config (
netstandard.txtin the root)