-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Behavior of dependency resolution #63617
Comments
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov Issue DetailsI ran into an issue, that when an assembly that was added as runtime asset through the framework (i.e. I have a somewhat complex setup:
We use one MSBuild that has PackageReferences on all tools and publish that csproj to get a folder that includes all DLLs that would work together. It's not possible to create a application specific dependency file for each tool, since only one for the whole folder is created. If I run the application with I create a MCVE that shows this behavior. Test.csproj
Program.cs
When publishing it, everything works. Once you remove the
Running this with
Since it's adding the one from the folder with Is there a way to enforce the versions to be loaded correctly from the local folder without referencing the deps-file? When referencing the deps-file, the line includes
|
I can't think of a way to do this without the I do know that the version comparison was added for exactly cases like this, where the app carries its own version of an assembly which also exists in the framework. And it intentionally picks the highest version because it can't blindly pick the one from the app (for example, if the app was built for .NET 3.1 using some custom 3.1 version of a framework assembly, then trying to run this app on .NET 6 needs to upgrade the dependency to 6 as well, otherwise the framework would not work). In all these cases we rarely consider apps without I understand that if you want to share assemblies between several apps it's problematic. We've been discussing ways to enable this but no concrete plans exist yet. For self-contained apps we're considering this: #53834. But it doesn't solve sharing non-framework assemblies. |
Thanks for your reply. I can understand, that it's hard to figure out, if the information is missing. But when I just rename the dependency file (to simulate the case, where I have the shared deps file), I would still assume, that it would behave exactly as if it would be using a deps file with the application name (or given using I ran it through dotnet exec --additional-deps _Test.deps.json Test.dll and dotnet exec --additional-deps _Test.deps.json Test.dll. The first looks pretty similar to if I would have not given it the dependency file at all. For easier comparison, have a look at this screenshot: Look especially for this line: I only found https://github.com/dotnet/runtime/blob/main/docs/design/features/additional-deps.md so maybe it is related to the change of order? The additional deps would be able to at least be set through My only other workaround would be, to copy the file to be found as application specific (which it isn't). From the applications perspective, these are additional, since they are not part of the tools build time dependencies. So even if I keep the one generated with the app, it's complaining, that it doesn't find the correct version. But due to those matching against the framework ones instead of the ones from the |
I think the additional deps doesn't work because:
Number 1 is processed first and added to the result. I didn't really test this manually though, so I could be wrong. |
It would at least explain the seen behavior. Is there any possible way (besides copy/renaming the deps file for each application) to hint the executable to use that one other than using the It would have been great, to have a fourth option of dependency file between the app-specific and the additional deps one, but being treated as strong as the app-specific one. So basically forcing the version defined there to be considered (instead of just adding them with -1). Basically, something along the line of
This third one feels broken to me, since all other are replacing version aware. Just this one isn't. So generating this combined |
I can't think of any other way right now. The |
If you can generate the file, while not simply create a copy for each app with the right name... sorry I must have missed something. |
I understand that. I would be fine if it's just checking in the same folder (like it's checking for a file named
It's not that I can't. I'm just trying to find out, if there is a better solution. Especially one that is good to automate. If there isn't, and if there are no plans to address this, the way I will tackle this is most probably to add a |
Unfortunately we don't have any specific plans to address this scenario right now - it may change, but it's unlikely we would make improvements in this area for .NET 6 - if anything happens it would be for .NET 7+. |
I fully understand that, especially since it's a very niche requirement. I mostly started this discussion to see if I'm understanding/observing it correctly or if I just missed something in plain sight. I'm also fine to just keep this as a low-priority "there's a use-case" reminder for .NET 7+ and using workarounds. Do you know, if there is a way to detect apphost instances through MSBuild (to find out which files need a |
If you're building the app itself, there is a variable which holds the name of the apphost (I would have to look for it), but in your setup where you're combining multiple apps through NuGets - I don't think there is anything (the fact that it's an apphost would have to be stored in the NuGet somewhere... ) |
Thanks for all the feedback. I will close this for now and work on my workaround :) Feel free to link this whenever it might become relevant for .NET 7+. |
I ran into an issue, that when an assembly that was added as runtime asset through the framework (i.e.
Microsoft.NETCore.App.deps.json
), when it's changed to a later version (i.e. through another PackageReference dependency), the application is crashing if the applications.deps.json
is missing.I have a somewhat complex setup:
.deps.json
file when the application is created.deps.json
is created that contains all information automaticallyWe use one MSBuild that has PackageReferences on all tools and publish that csproj to get a folder that includes all DLLs that would work together. It's not possible to create a application specific dependency file for each tool, since only one for the whole folder is created. If I run the application with
dotnet exec --depsfile <GenerationProject>.deps.json <ToolName>.dll
, everything works fine. Running it withoutdepsfile
argument, I would still expect the apphost's runtime to prefer the DLL that is in the probe directory over any version coming from the framework. Sadly, that's not the case. It will replace the one found in the framework.I create a MCVE that shows this behavior.
Test.csproj
Program.cs
When publishing it, everything works. Once you remove the
Test.deps.json
, you will get:Running this with
COREHOST_TRACE
on, I was able to trace the issue down to this:Since it's adding the one from the folder with
AssemblyVersion: , FileVersion:
, it seems to find the one from the framework to be more specific or the correct one.The version 5 of
System.Collections.Immutable
is coming from referencingMicrosoft.CodeAnalysis.CSharp.Scripting
which itself referencesMicrosoft.CodeAnalysis.Common
, so it's nothing that I have a lot of influence on. In my real application, I reference the scripting package in a library targetingnetstandard21
which then is referenced itself by two bootstrappers, one for .NET Core 3.1 and one for .NET 5. So I also would not want to force the DLL to a specific version, as I expect the publishing step to take care of this as part of the resolution phase.Is there a way to enforce the versions to be loaded correctly from the local folder without referencing the deps-file? When referencing the deps-file, the line includes
System.Collections.Immutable.dll, AssemblyVersion: 5.0.0.0, FileVersion: 5.0.20.51904
. Sadly, also using--additional-deps
is not helping, since it's also resolved usingAssemblyVersion: , FileVersion:
and gets replaced by the older version. So I found no other working solution than calling the application with the--depsfile
, copying the combined.deps.json
for each tools filename or by implementing the handlerAppDomain.CurrentDomain.AssemblyResolve
to load the one from the folder manually at runtime in each tool.The text was updated successfully, but these errors were encountered: