aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
256 stars 124 forks source link

Project specific .deps.json file includes project referenced DLLs not directly referenced DLLs #928

Open jbrackin01 opened 7 years ago

jbrackin01 commented 7 years ago

When attempting to include a reference that is the output of a DLL library solution, the project using a class in the referenced DLL will build but fails at runtime with an error suggesting the project is missing a reference.

If the project that builds the DLL is included in the same solution, the solution builds and works at runtime.

Comparing the output directories the only differences appear in the file Localisation.deps.json. When the project is included in the solution and the reference is a project reference and not a previous built DLL reference the following appears in the Localisation.deps.json file:

"targets": { ".NETFramework,Version=v4.5.2": { "localisation/1.0.0.0": { "dependencies": { "CSharpLog": "1.0.0",

  ...

  "csharplog/1.0.0": {
    "compile": {
      "CSharpLog.dll": {}
    }

  ...

".NETFramework,Version=v4.5.2/win7-x86": {
  "localisation/1.0.0.0": {
    "dependencies": {
      "CSharpLog": "1.0.0",

 ...

  "csharplog/1.0.0": {
    "runtime": {
      "CSharpLog.dll": {}
    }
  }

If I build the solution using a reference to the previously built DLL and make the updates above to the file Localisation.deps.json then the code runs same as it does when the project is referenced in the solution.

The issue seems to be simply that project references updates this file and DLL references do not.

Thanks

jbrackin01 commented 7 years ago

After the original post I created a simplified solution to replicate the issue. See attached zip file WebAppReferences.zip

The solution contains the follows:

When I first did this both the WebAppReferencesDLL and WebAppReferencesProject worked which was a bit unexpected.

Eventually determined the difference was if an object in the Utils.dll was used directly in the Razor syntax. Doing this resulted in the same issue, the WebAppReferencesDLL builds but fails at run time. The error displayed is: An error occurred during the compilation of a resource required to process this request. Please review
the following specific error details and modify your source code appropriately.

/Views/_ViewImports.cshtml

The type or namespace name 'Utils' could not be found (are you missing a using directive or an assembly reference?) @using Utils

I've included at the solution file level two versions of the WebAppReferencesDLL.deps.json file: WebAppReferencesDLL.deps_Failing.json WebAppReferencesDLL.deps_Working.json

Replacing the WebAppReferencesDLL.deps.json file with the WebAppReferencesDLL.deps_Working.json file will allow the WebAppReferencesDLL to work at runtime.

Is it simply when using a DLL reference that the assembly needs to be added differently to allow page level access? Thinking something similar to the web.config file entries for assemblies. If so, why does a project reference automatically assume page level access while DLL references need additional steps?