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

deps.json has a bug when dll version is end with zero #3522

Closed
cyq1162 opened this issue Mar 27, 2019 · 16 comments
Closed

deps.json has a bug when dll version is end with zero #3522

cyq1162 opened this issue Mar 27, 2019 · 16 comments
Milestone

Comments

@cyq1162
Copy link

cyq1162 commented Mar 27, 2019

Steps to reproduce

I try to put the Microsoft..dll and System..dll togather to a new folder.
以便把(第三方或)系统的和应用的dll分开。
之前花了很长的一段时间研究之后:
I find xxx.deps.json can make it work.
之后我还特意写了篇文章介绍它:https://www.cnblogs.com/cyq1162/p/10542832.html
but today,when i update the Microsoft. Aspnetcore to 2.2.0 version.
it dose not work, and make me crazy.

because it always show me the msg like this:

F:\Code\OpenSource\Aries-GitHub\trunk\Aries.DevFramework\Web.UI_NetCore\bin\Rele ase\PublishOutput>dotnet Web.UI.dll Error: **An assembly specified in the application dependencies manifest (Web.UI.deps.js on) was not found**: package: 'Microsoft.AspNetCore.Authentication.Abstractions', version: '2.2.0 ' path: 'lib/netstandard2.0/Microsoft.AspNetCore.Authentication.Abstractions.d ll'
and the json like this:

"Microsoft.AspNetCore.Authentication.Abstractions/2.2.0": {
        "dependencies": {
          "Microsoft.AspNetCore.Http.Abstractions": "2.2.0",
          "Microsoft.Extensions.Logging.Abstractions": "2.2.0",
          "Microsoft.Extensions.Options": "2.2.0"
        },
        "runtime": {
          "lib/netstandard2.0/Microsoft.AspNetCore.Authentication.Abstractions.dll": {
            "fileVersion": "2.2.0.18316"
          }
        }
      }

我花了N长的时间在检测配置和确定路径的正确性,但结果,却依旧很悲催。
it take me much time to find out the question what it's.
when i try to maike it like this:
Microsoft.AspNetCore.Authentication.Abstractions
Microsoft.AspNetCore.Authentication.Abstractions/2.2.xxx
it work.
就是这样,只要版本号不是2.2.0,它就一切正常。
之后又几次测试,发现版本号是4.6.0也同样有问题。
and then i find the version on /4.6.0 ,it does not work also.
就是这样,版本号三位数,尾数是0的,就提示找不到dll。
how ugly this bug it's.

@vitek-karas
Copy link
Member

Can you please answer some of these questions to help us better understand the problem?

  • What type of application is this? Can you repro the problem with a simple dotnet new <something> and some modifications...?
  • Based on the article you reference, you're trying to modify the .deps.json to reduce files in the published directory. I'm wondering what the app is doing to get into the situation with lot of files in the output folder. When I do a dotnet new razor (for example), I get an ASP.NET application which has only about 10 files total in the output folder.
  • Can you please set environment variable COREHOST_TRACE=1 and then run your app (which reproes the problem) with 2>trace.log at the end of the command line. And then if possible share the trace.log with us (it does contain file paths from your machine, so please do so only if you're comfortable sharing that).

@cyq1162
Copy link
Author

cyq1162 commented Mar 28, 2019

ok,i try it again.
1、I have a mvc website:http://mvc.taurus.cyqdata.com, it run on CentOS7,at first it deploy like this :

and now it make it like this by *.deps.json:

I put the Microsoft.xxx.dll or System.xxx.dll to another folder like package.
how I do that ? I replace all the path lib/netstardardxxxx to my path.

so it work well at Microsoft.AspNetCore.All 2.0.3 version.
but my question is :when i update to 2.2.0 version,it dose not work.

if i change the version to anything like 2.2.x,it will work well.
I find it have the same bug on linux and windows. now ,you kown what i say ?

@vitek-karas
Copy link
Member

Thanks a lot for the detailed description.

About the error:
I tried an empty razor app on .NET Core 2.2, and forced it to have a reference to Microsoft.ApplicationInsights/2.4.0 - so my .deps.json looks very similar to yours, but it works just fine.
What I find weird is that you're saying you're trying to use ASP.NET 2.2, but the .deps.json above shows that you're using .NETCoreApp, Version=v2.1. Can you please share the content of your .runtimeconfig.json?

About the problem with lot of files in the output:
Does your .runtimeconfig.json have a framework reference to Microsoft.NETCore.App or to Microsoft.AspNetCore.App?

@cyq1162
Copy link
Author

cyq1162 commented Mar 28, 2019

OK,I try it again.
I make a SourceCode and Demo,you can download on (5M) : http://mvc.taurus.cyqdata.com/WebPublish.rar
unrar and "dotnet Taurus.View.dll" on cmd,you will get the error message like:

and you replace 2.2.0 to 2.2.1 at Taurus.View.deps.json like this,and run again,it will be ok.

you you need the source code for building, you can download on (917K) : http://mvc.taurus.cyqdata.com/SourceCode.rar

@vitek-karas
Copy link
Member

Thanks a lot.

The immediate failure is caused by a missing file. The Microsoft.AspNetCore.Authentication.Abstraction.dll is in fact not there. So it fails correctly.

If you change the version you effectively corrupt the .deps.json. The entire string Microsoft.AspNetCore.Authentication.Abstraction/2.2.0 is a package identifier, which should exist in the libraries section near the end of the .deps.json file. As is the package section exists. If you change the version it won't find the package. I guess it's a bug that it won't fail in that case, in fact it simply ignores the assembly if it can't find the matching package section. This is definitely not expected, but I doubt we can fix it (if somebody relies on this behavior we would break them).

The app runs without the assembly just fine, at least the startup as I assume it doesn't need it. If it would run into code which needs it, it would fail at runtime.

Note that when I built it from source, it worked without any modifications (as the file was present).

As for the number of additional files in the app. I took your solution, changed all projects to target netcoreapp2.2 (since you're trying to use ASP.NET Core 2.2, it makes sense to target 2.2 for everything). And then I added this line to the Taurus.View_NetCore.csproj

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

Now when I publish the solution, I get only about 20 files in the output. Basically just the application plus 2 additional System.* assemblies.

@cyq1162
Copy link
Author

cyq1162 commented Mar 28, 2019

To facilitate the presentation of the problem,
I put Microsoft. AspNetCore. Authentication. Abstraction. dll in the Lib directory, and then the path of the configuration file was modified to point to it, so the file is supposed to exist, even if it is not used in the project, but the direction of the path is right, I don't know if you notice it.

Version number is no problem, after all, it is automatically generated by the system.


In addition, the 2.2.0 I mentioned above refers to the Nuget version package of ASPNET Core. It is not. NetApp version upgraded to 2.2. App version is still using 2.1.

@vitek-karas
Copy link
Member

I'm sorry - I don't understand your comment about the version number not being a problem. It is by design that the run fails if .deps.json refers to a file which it can't find, so in your repro, the fact that it fails is expected.
I do agree that the fact that if the version number is changed (and thus doesn't match the package in the libraries section) the run will simply ignore the problem and the file and just continue is a bug. I have my doubts we would fix it though as it might break people.
By doing this the .deps.json becomes invalid, and the current error checking is somewhat simplistic on .deps.json - this is basically expected, as the .deps.json is not meant to be used by humans - it is meant to be machine generated, and thus it's reasonable to expect correct input.

As for ASPNET Core versioning - I'm honestly surprised you can even run ASP.NET 2.2 on .NET Core 2.1, but I'm no expert in ASP.NET deployment.

To explain why you get so many files in the output:

  • Normally .NET Core apps rely on "shared frameworks" which live in the global installed location. These are referenced from the .runtimeconfig.json. You can see that your app references Microsoft.NETCore.App there, which is the root framework (contains CoreCLR and CoreFX).
  • ASP.NET itself contains lot of assemblies. Again by default this will be recognized as a "shared framework" and you would get a reference to Microsoft.AspNet.Core.App in your .runtimeconfig.json.
  • If one of the referenced shared frameworks contains the required assembly, then that assembly is not included in the output of the app. So by default you don't get pretty much any "Microsoft." or "System." assemblies in the app as those are all in the shared frameworks.
  • In your case I can only assume the build system is confused a bit - you require ASPNET Core 2.2 on .NET Core 2.1. Since no such shared framework exists, it probably just brings all the ASP.NET assemblies into the app. By migrating all projects to .NET Core 2.2 you give the build system a way to rely on shared frameworks instead. For some reason the PackageReference to ASPNET also has to be in the main project for this to work (no idea why).
  • Once that is done, your app should have a reference to Microsoft.AspNet.Core.App version 2.2 which in turn has a reference to Microsoft.NETCore.App version 2.2. And so the build system will be able to avoid all the system assemblies in the app and solely rely on the shared frameworks.

@cyq1162
Copy link
Author

cyq1162 commented Mar 29, 2019

i mean,when you down from http://mvc.taurus.cyqdata.com/WebPublish.rar
and unrar , you will find lib/Microsoft. AspNetCore. Authentication. Abstraction. dll and this dll version is 2.2.0. the file is exists.
and the Taurus.View.deps.json , you look,it point to the same path.

so,tell me ,why can't find it ,the related path is error ?

@vitek-karas
Copy link
Member

Sorry I didn't understand your original concern. I see what you mean now.
For some reason (I can really only speculate, I was not around when this code was introduced), relative paths for "normal" assemblies are basically ignored and the assemblies are expected to live in the main folder of the app.

I don't think there's a way to simply redirect some assemblies into a different location. It can be done if the alternative location mimics NuGet cache folder structure. But a flat list is not possible right now (I think).

Please note that if you change the version to 2.2.1 as you mention in your screenshot, it will NOT be OK. The assembly is simply ignored, but if it is actually needed at runtime, the runtime won't find it.

@cyq1162
Copy link
Author

cyq1162 commented Mar 29, 2019

I have to tell you, It' work on ASPNETCore 2.0.3 version。

I put all the dll to a new folder,so the runtime will use it. ------------------------- at this demo, i just put one dll for showing the problem. the only different is to use version 2.0.3 or verson 2.2.0. if you still have some question,maybe i have to make a ok demo on version 2.0.3 of the same way.

@vitek-karas
Copy link
Member

Can you please just show me the .runtimeconfig.json from the app which worked like this before?
Also note (as I mentioned above) - it does work for packages, but those are not in a flat folder structure (and it needs some additional stuff in the .deps.json).
That's how it works for simple dotnet build - in that case the additional files are not in the "app" and they are in various package folders. Those are searched via additionalProbingPaths which are specified in .runtimeconfig.dev.json.

Once the app is published via dotnet publish that goes away and all the assemblies from the packages are copied into the output.

@cyq1162
Copy link
Author

cyq1162 commented Mar 29, 2019

Thank you for reminding me。
I find something in the Taurus.View.runtimeconfig.json

and that ' s what make it work well. -_-.....
That's what I used to do in my experiments, so I never noticed it.
thanks a lot.

@vitek-karas
Copy link
Member

Yes - that will make it look for packages in those directories and as long as those directories have the right structure it will work.

Regardless, if you plan to update to ASP.NET 2.2, I would highly recommend you update to NETCore 2.2 as well and use the shared frameworks as I mentioned above.

@vitek-karas
Copy link
Member

I created dotnet/core-setup#5643 for the "not failing on invalid .deps.json" problem.

@vitek-karas
Copy link
Member

I created dotnet/core-setup#5645 for the "ignore relative path" problem.

@vitek-karas
Copy link
Member

It seems this is now resolved. The uncovered problems were filed as separate issues.
If there are still unresolved problems, feel free to reopen this or a new issue.

@msftgits msftgits transferred this issue from dotnet/core-setup Jan 30, 2020
@msftgits msftgits added this to the Future milestone Jan 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants