-
Notifications
You must be signed in to change notification settings - Fork 419
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
Added support for csproj-based scripts #980
Conversation
Looks like logging broke. Looking into it |
Looks like the old Dotnet.Script.NuGetMetadataReferenceResolver pulled in Microsoft.Extensions.Logging 1.1.1. Without it logging starts to fail all over |
🎉 ✨ 👑 |
Got it. Binding redirect for Microsoft.Extensions.Logging needs to be 1.1.0.0 now that we don't pull in 1.1.1.0 anymore. Fixing |
_compilationDependencyResolver = new CompilationDependencyResolver(type => | ||
{ | ||
// Prefix with "OmniSharp" so that we make it through the log filter. | ||
var categoryName = $"OmniSharp.{type.FullName}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this maybe needs one more level nesting for better context i.e. OmniSharp.Script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, outside the one minor question about logging.
{ | ||
dependencyResolverLogger.LogDebug(message); | ||
} | ||
if (level == LogLevel.Info) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any other related log levels (that matter?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that’s it. No other levels 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean it will only log informational messages if the LogLevel == Info? I would expect it to send informational messages if LogLevel <= Info. Same for debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are only two possible levels logged from Dotnet.Script.DependencyModel
- Debug = 0
- Info = 1
I would expect it to send informational messages if LogLevel <= Info.
Debug
is the lowest level and it would sound a little strange to me to log that as a informational message?
The LogLevel
that we pass into the delegate is not from Microsoft.Extensions.Logging
. It is defined in Dotnet.Script.DependencyModel
with only those two levels.
Dotnet.Script.DependencyModel
does not depend on Microsoft.Extensions.Logging
. The code here simply forwards log messages to the actual logging framework which for OmniSharp.Roslyn means Microsoft.Extensions.Logging
Did that make any sense ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I thought these were coming from Microsoft.Extensions.Logging
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured you might think so:) Didn’t want to introduce a shared library version problem again. Therefore we don’t reference Microsoft.Extensions.Logging.
Are we good to rock'n roll on this one? |
Yeah let's punch this in - we are now in a really nice place on the scripting side. Thanks! |
@@ -37,11 +37,11 @@ | |||
|
|||
<dependentAssembly> | |||
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral"/> | |||
<bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0"/> | |||
<bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.0.0"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these got added because Dotnet.Script.NuGetMetadataResolver
depended on 1.1.1. So, it might be that these could just be removed now.
</dependentAssembly> | ||
<dependentAssembly> | ||
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/> | ||
<bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.1.0"/> | ||
<bindingRedirect oldVersion="0.0.0.0-1.1.1.0" newVersion="1.1.0.0"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want me to PR removal of these redirects?
This PR adds support for csproj-based scripts and marks the end of supporting
project.json
as a way to resolve compilation dependencies for C# scripts.The dependency to the Microsoft.DotNet.ProjectModel package is gone and we now resolve compilation dependencies using the Dotnet.Script.DependencyModel package being maintained in the Dotnet.Script repo. See the release notes for Dotnet.Script 0.14.0 for more details
For scripts that contain inline NuGet references, we still have this as an opt-in feature as before.
Nothing has changed for scripts that targets the full framework. This PR only affects scripts that targets .Net Core.
With this update to the project system we can now resolve compilation dependencies for all packages that targets
netstandard2.0
.The following section provides more details about the packages now being referenced from OmniSharp.Script
Dotnet.Script.DependencyModel
Provides an API to resolve runtime and compilation dependencies for csproj-based scripts.
This library has no dependencies to other
dotnet.script
libraries or other third-party packages, which means that it can be used by all script runners that needs to resolve runtime dependencies.In addtion to being compiled for
netstandard2.0
, it is also compiled fornet46
so that it can be used fromOmniSharp.Scripting
Dotnet.Script.DependencyModel.NuGet
This package contains ONLY the
NuGetMetadataReferenceResolver
that is used to handle inline NuGet package references.This
MetadataReferenceResolver
does not really do anything besides allowing the actual NuGet reference and returning an assembly reference.Prerequisites
The
Dotnet 2.0 sdk
will have to be installed since we usedotnet restore
under the hood to provide aDependencyContext
from which we resolve runtime and compilation dependencies. On the execution side ,this is not a problem since the user would have to have thedotnet cli
installed anyway to executedotnet.script
. On the OmniSharp side, relying on thedotnet cli
might sound a little more questionable. But sincedotnet.script
is the only script runner that actually understands either an explicitcsproj
file or acsproj
file generated from script NuGet references, we should be good also on the OmniSharp side. In the event of thedotnet cli
being unavailable, we will restore script packages using NuGet version 4.3.0 that comes embedded withDotnet.Script.DependencyModel.
Logging
Instead of relying on a logging framework, we simply provide a delegate that can be used from the consuming library to forward log messages to the actual logging framework.
This is to done to reduce the number of third party dependencies needed by
Dotnet.Script.DependencyModel
Example:
Resolving runtime dependencies (Execution)
Resolving packages with native/unmanaged dependencies
Some NuGet packages ship with native/unmanaged libraries. An example would be the Microsoft.Data.SQLite package that relies on the
e_sqlite3
native library. This library needs to be accessible and discovered by the scripting runtime and we do that on Windows usingLoadLibrary
.It is sort of a hack, but it seems to make the scripting runtime aware of the DLL. Preferably we would somehow set the
NATIVE_DLL_SEARCH_DIRECTORIES
property of the AppDomain, but we can't do that once the CoreHost is up and running. We simply come in to late.The
LoadLibrary
method can only be used on Windows, but the *nix counterpart,dlopen
does not do the trick here.Resolving compilation dependencies (OmniSharp)
Compilation dependencies (or compile-time dependencies) are meant to be used by
OmniSharp.Script
to provide intellisense for script files.Say goodbye to project.json
For a long time during the beta days of .Net Core, it looked like Microsoft was heading for a new project format for .Net projects.
project.json
was introduced as the new lightweight project format and a lot of time and effort was put in to convert projects from the oldcsproj
format to this new shinyproject.json
format. After a while or more specifically towards the end of the beta period, Microsoft decided to ditch project.json and go back to csproj. Not the old and rather verbose csproj, but a new simpler csproj format.project.json
practically died over night.OmniSharp.Script still uses
project.json
as a way to provide a "runtime context" from which the compilation dependencies can be retrieved. Thisproject.json
file can contain references to NuGet packages and hence OmniSharp can provide intellisense for them as well.The problem with
project.json
today is that we barely have any tooling left that can understand the format. NuGet stopped supportingproject.json
after version 3.5 and the dotnet sdk never understood the format after going out of beta. So for instance, if you want to useproject.json
today , you will need an outdated preview version of the dotnet sdk that most developers do not install.