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

upgrade asp.net core targeting framework 4.6.1 from vs2015 to vs2017 - One or more compilation references are missing #958

Closed
ErezSavir opened this issue Mar 8, 2017 · 20 comments

Comments

@ErezSavir
Copy link

have upgraded my asp.net core,using project.json and targeting .net framework 4.6.1 on visual studio 2015 to visual studio 2017.

I have multiple projects in the solution where the main application is referencing them by project reference(all of them target net461).

When running the application I get

One or more compilation references are missing. Possible causes include a missing 'preserveCompilationContext' property under 'buildOptions' in the application's project.json.
Screenshot:
11

And my csproj:
webapp.txt

I'll try to create a project to see if I can reproduce.

@livarcocc
Copy link
Contributor

how are you running your project? I would not expect project.json to be referenced at all when running a migrated (csproj) project.

@ErezSavir
Copy link
Author

ErezSavir commented Mar 8, 2017

I have tried via VS2017 and multiple cli version (even tried the nightly alpha build).

Did not understand what you meant by the second statement? can you please explain?
If you referred to the error, i think the error message was not updated(?)

@livarcocc
Copy link
Contributor

The error message that you pasted above:

One or more compilation references are missing. Possible causes include a missing 'preserveCompilationContext' property under 'buildOptions' in the application's project.json.

It mentions properties that exist in project.json and mentions project.json. But my understanding is that you have migrated to csproj.

So, my guess is that you are using a project.json based CLI to run your project. Can you check if you have a global.json file in the root of you repo and if it has a version property in it pointing to preview2 or preview2-1 of the CLI. The property should be under sdk in the global.json.

@ErezSavir
Copy link
Author

I don't have global.json(I deleted the file before the migration). I'm mainly running via visual studio. I assume vs uses it owns tools therefore the version installed is not relevant?(correct me if i'm wrong).
Regardless, I have tried the latest version with the same result(also the same error message)

@dasMulli
Copy link
Contributor

dasMulli commented Mar 8, 2017

@livarcocc
Copy link
Contributor

cc @mlorbetske

@mlorbetske
Copy link
Contributor

mlorbetske commented Mar 9, 2017

@vijayrkn @dsplaisted it looks like the compilation context hasn't been preserved even though it's set in the project file, any ideas?

cc @Eilon for the hard coded string

@Eilon
Copy link
Member

Eilon commented Mar 9, 2017

Derp. I filed aspnet/Mvc#5931 to track fixing MVC's bad error message.

@ErezSavir
Copy link
Author

Update - Created a new project from VS template, copied all the source code into the new project and it's working. I don't know why but something in the migration process was 🙈.
Also, there is no preserveCompilationContext in my csproj anymore. Thoughts?

@mlorbetske
Copy link
Contributor

@ErezSavir the PreserveCompilationContext flag is set by default to True in Microsoft.NET.Sdk.Web, so it's not required to be present in the project file. Migration likely adds it as this setting is not web specific, but it's not defaulted on the other SDKs

@mlorbetske mlorbetske reopened this Mar 9, 2017
@mlorbetske
Copy link
Contributor

Sorry, closed by accident

@nguerrera
Copy link
Contributor

@ErezSavir We still need to track down the migration issue. Can you provide a repro with a project.json project that ends up in this bad state after migration?

@ErezSavir
Copy link
Author

@nguerrera I didn't managed to repro the issue. I can upload the original projects project.json if it would help.

@nguerrera
Copy link
Contributor

nguerrera commented Mar 13, 2017

@ErezSavir So, as of now, if you dotnet migrate the original project.json, the resulting csproj works fine?

@livarcocc
Copy link
Contributor

Since this does not seem to be a problem anymore and we can't repro the issue, I am closing it. Please, re-activate if you run into it again and provide the original project.json that migrated to a bad state.

@AlexBar
Copy link

AlexBar commented May 21, 2017

@livarcocc
Looks like I found a way how to reproduce it:

  1. Create a new "ClassLibrary2", targets "net461".
  2. Create a new ASP.NET CORE app, targets "net461"
  3. Build ClassLibrary2 project into dll
  4. Add reference for web app to this dll
  5. Add to some razor page "using ClassLibrary2" (ClassLibrary2 - default namespace for the library)
  6. Run web app and you will see this error
    "The type or namespace name 'ClassLibrary2' could not be found (are you missing a using directive or an assembly reference?)

@using ClassLibrary2

example: WebApplication1.zip

@dsplaisted dsplaisted reopened this May 22, 2017
@sjaase
Copy link

sjaase commented Jun 21, 2017

This seems related to an issue I had with Visual Studio 2017 when I moved from VS2015.

If you have targetframework = net461 and you have mscorlib.dll in your project folder or subfolders (not bin, obj), you will get the "One or more compilation references are missing" error message.

This can happen if you publish to a folder other than the default bin directory, e.g. to publish subfolder in project folder where mscorlib.dll will be copied and other dll's.

If you build using the dotnet cli from the command line, mscorlib.dll needs to be in the root project folder for the issue to appear. If you are using Visual Studio 2017 to build your project, mscorlib.dll can be in any subfolders.

To reproduce it:

  • Create a ASP.NET Core Webapplication in VS2017.
  • Change targetframework to net461
  • Create a subfolder in the project folder e.g. "publish" and put mscorlib.dll in it.
  • Build the project (or rebuild if it was built).
  • Run the web application and error should appear.

@dominicrooijackers
Copy link

I got the same error message, in my case I had to fully qualify my Model (@model Project.Namespace.Classname) and then it worked.

Best regards
Dominic Rooijackers

@GeorgDangl
Copy link

I'm encountering the issue with a just-migrated project:
https://github.com/GeorgDangl/xbim-meets-angular

Is there already some workaround available?

@livarcocc
Copy link
Contributor

We have no plans to continue to change dotnet migrate at this moment. As such, I am going to close this issue.

mmitche pushed a commit to mmitche/sdk that referenced this issue Jun 5, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…0190912.1 (dotnet#958)

- Microsoft.AspNetCore.Mvc.Analyzers - 5.0.0-alpha1.19462.1
- Microsoft.AspNetCore.Mvc.Api.Analyzers - 5.0.0-alpha1.19462.1
- Microsoft.AspNetCore.Analyzers - 5.0.0-alpha1.19462.1
- Microsoft.AspNetCore.Components.Analyzers - 5.0.0-alpha1.19462.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests