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

Don't reference netstandard1.x packages #74199

Closed
wants to merge 2 commits into from

Conversation

ViktorHofer
Copy link
Member

@ViktorHofer ViktorHofer commented Jun 28, 2024

... when building from source.

This was the only remaining project in roslyn that brought them in.

Contributes to dotnet/source-build#4482

... when building from source.

This was the only remaining project in roslyn that brought them in.
@ViktorHofer ViktorHofer requested a review from a team as a code owner June 28, 2024 07:54
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 28, 2024
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Jun 28, 2024
@ViktorHofer ViktorHofer requested a review from a team as a code owner June 28, 2024 07:56
@jjonescz
Copy link
Member

@ViktorHofer source build is failing

@ViktorHofer
Copy link
Member Author

ViktorHofer commented Jun 28, 2024

@MichalStrehovsky just to double check, src/Scripting/Core/Microsoft.CodeAnalysis.Scripting.csproj shouldn't be referencing the old System.Runtime.Loader package on netstandard2.0 and we should convert AssemblyLoadContext usages to AssemblyLoader when targeting netfx or netstandard, right?

@MichalStrehovsky
Copy link
Member

@MichalStrehovsky just to double check, src/Scripting/Core/Microsoft.CodeAnalysis.Scripting.csproj shouldn't be referencing the old System.Runtime.Loader package on netstandard2.0 and we should convert AssemblyLoadContext usages back to AssemblyLoader when targeting netfx or netstandard, right?

Yeah, I don't think the System.Runtime.Loader would do anything good on netfx. Cc @dotnet/appmodel

@ViktorHofer
Copy link
Member Author

What makes this problematic is that Microsoft.CodeAnalysis.Scripting dynamically instantiates either an AssemblyLoadContext or an AssemblyLoader:

public static AssemblyLoaderImpl Create(InteractiveAssemblyLoader loader)
{
if (CoreClrShim.AssemblyLoadContext.Type != null)
{
return CreateCoreImpl(loader);
}
else
{
return new DesktopAssemblyLoaderImpl(loader);
}
}

@ViktorHofer
Copy link
Member Author

cc @jaredpar @MichaelSimons @ericstj

The goal is to remove all netstandard1.x package dependencies when building from source (see dotnet/source-build#4482). Roslyn is one of the few remaining repos that bring a netstandard1.x package in. For roslyn it's only a single reference in a single place: System.Runtime.Loader/4.3.0 by Microsoft.CodeAnalysis.Scripting.csproj.

See my comments above. It's hard to get rid off that package as roslyn dynamically instantiates either an ALC or AssemblyLoader.

@ViktorHofer ViktorHofer marked this pull request as draft June 28, 2024 13:11
@jaredpar
Copy link
Member

@tmat, @arkalyanms FYI

@ericstj
Copy link
Member

ericstj commented Jun 28, 2024

For roslyn it's only a single reference in a single place: System.Runtime.Loader/4.3.0 by Microsoft.CodeAnalysis.Scripting.csproj.

As a workaround you could PackageDownload then raw-reference the file. That will avoid pulling the dependencies.

@ViktorHofer
Copy link
Member Author

As a workaround you could PackageDownload then raw-reference the file. That will avoid pulling the dependencies.

Yes, I considered that. The goal here is to remove all netstandard1.x packages. If we keep the System.Runtime.Loader reference then we would need to continue building it in SBRP including its dependencies.

@jaredpar
Copy link
Member

The compiler approaches this by representing assembly loading through an interface at the netstandard2.0 layer. Then we have our .NET Framework / Core implementations that are fed through by the host. The actual host is going to target Core or Framework so it can be definitive in what it references.

That model was designed into the compiler very early on though. Not sure if the scripting layer can take this approach or not.

@arkalyanms arkalyanms requested a review from tmat June 28, 2024 17:03
@ViktorHofer
Copy link
Member Author

ViktorHofer commented Jul 8, 2024

@tmat can you please take a look? We need to stop referencing netstandard1.x packages directly as those will eventually be marked as deprecated and together with NuGet's new Audit mode, such package references will result in errors.

@ViktorHofer
Copy link
Member Author

@arkalyanms / @jaredpar can you please help me find someone to take a look at this? I will be out for an extended time starting in about two weeks and would ideally want to complete this by then.

@jaredpar
Copy link
Member

can you please help me find someone to take a look at this?

What are you looking for feedback on? Is the PR as written not meeting the goal here of removing netstandard1.x packages?

@ViktorHofer
Copy link
Member Author

The changes in this PR aren't complete as when building from source, the src/Scripting/Core/Microsoft.CodeAnalysis.Scripting.csproj project also gets built for netstandard2.0 (which I realized after opening this PR and hence converted it to draft). When building for netstandard2.0, the System.Runtime.Loader package is still referenced.

I'm trying to understand how to avoid the package reference entirely and if such a change would be acceptable. As mentioned above, this will help the regular (msft) build and source-build as we will eventually deprecate these packages.

@tmat
Copy link
Member

tmat commented Jul 16, 2024

Scripting uses reflection light-up. If the app that loads the library runs on .NET Framework we use desktop AssemblyLoader via reflection. If it runs on .NET Core we use ALC (directly - hence the reference to System.Runtime.Loader).

The project is now multi-targeting so I think we can use #ifdef instead of light-up.

@ViktorHofer
Copy link
Member Author

Searching through the dotnet GH org I found a few projects that currently target .NET Standard and rely on the "Microsoft.CodeAnalysis.Scripting.Common" package.

If we remove the netstandard2.0 TFM, then we would also need to at least update these projects.

The project is now multi-targeting so I think we can use #ifdef instead of light-up.

That sounds right to me. @tmat can you help with that?

@tmat
Copy link
Member

tmat commented Jul 16, 2024

Working on it.

@tmat
Copy link
Member

tmat commented Jul 16, 2024

PR ready: #74409

@ViktorHofer
Copy link
Member Author

Closing in favor of #74409

@ViktorHofer ViktorHofer deleted the patch-3 branch July 17, 2024 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interactive Community The pull request was submitted by a contributor who is not a Microsoft employee. untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants