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

Roslyn does not load ASP.NET Core 2 documents #21660

Closed
CamiloTerevinto opened this issue Aug 22, 2017 · 12 comments
Closed

Roslyn does not load ASP.NET Core 2 documents #21660

CamiloTerevinto opened this issue Aug 22, 2017 · 12 comments
Assignees
Milestone

Comments

@CamiloTerevinto
Copy link

Version Used: Visual Studio 15.3.1

Steps to Reproduce:

  1. Create a solution with ASP.NET Core 2 over .NET Framework 4.7
  2. Create another solution with a Console Application over .NET Framework 4.7
  3. Use the following code to compile the ASP.NET Core project:
var workspace = MSBuildWorkspace.Create();
var solution = await workspace.OpenSolutionAsync(solutionPath);
var compilation = await solution.Projects.Single().GetCompilationAsync();
var result = compilation.Emit(memoryStream);

Expected Behavior:
The memoryStream, when written to a file, contains the correct DLL which, when read, has the types defined in the ASP.NET Core project (like Program, Startup, Controllers, etc).

Actual Behavior:
The project has HasDocuments = false and the generated DLL does not contain any type. See this SO question for further details

@Pilchie Pilchie removed their assignment Aug 22, 2017
@CamiloTerevinto
Copy link
Author

Looking at the Worskpace after loading the solution, I have an error message on the Diagnostics property:

Msbuild failed when processing the file 'D:\MyWebProject.csproj' with message: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.

@DustinCampbell
Copy link
Member

Unfortunately, MSBuildWorkspace does not support .NET Core projects very well yet. We're working on it but don't have an estimate of when it will be done.

@CamiloTerevinto
Copy link
Author

@DustinCampbell is there any other approach I could be taking? Maybe a nightly build or executing through command line?

@DustinCampbell
Copy link
Member

There's nothing available yet (work quite literally began this week 😄). There are some tricks you can try to workaround but I have no idea how well they might work.

For the particular error above you might consider setting the "MSBuildSdksPath" environment variable to the location of the appropriate .NET Core SDK on your machine before creating the MSBuildWorkspace. For example, on my machine, I might have the following:

Environment.SetEnvironmentVariable("MSBuildSdksPath", @"C:\Program Files\dotnet\sdk\2.0.0");

@CamiloTerevinto
Copy link
Author

@DustinCampbell I tried with both 2.0.0 and 2.0.1 preview, didn't make a difference. Notice, though, that before setting that variable, it is not set (GetEnvironmentVariable returns null).

Would it possible to run dotnet msbuild with Process or something alike?

@DustinCampbell
Copy link
Member

"MSBuildSdksPath" is an override that MSBuild looks for. If set, it will try and use it when handling the "Sdk" attribute. Honestly, it was a bit of a long shot to see if it would work.

Would it possible to run dotnet msbuild with Process or something alike?

I'm not sure what you mean by this.

@CamiloTerevinto
Copy link
Author

@DustinCampbell I was referring to something like this: https://docs.microsoft.com/en-us/dotnet/core/tools/cli-msbuild-architecture but running from C#.

Is there any property I can check to see whether the variable is being used at all?

@DustinCampbell
Copy link
Member

Is there any property I can check to see whether the variable is being used at all?

Unfortunately, no.

@DustinCampbell I was referring to something like this: https://docs.microsoft.com/en-us/dotnet/core/tools/cli-msbuild-architecture but running from C#.

Sure, I just didn't understand how it's relevant. MSBuildWorkspace uses MSBuild inproc. It's not related to the .NET CLI at all.

@BjarkeMeier
Copy link

@DustinCampbell What is the current status? I still have the same problem. Is there any known solution or workaround to get access to the semantic model of a solution (*.sln) having .NET Core projects?

@AlexeiScherbakov
Copy link

@BjarkeMeier did you try Microsoft.Build.Locator?

var vsVersions = MSBuildLocator.QueryVisualStudioInstances().ToArray();
var vsVersion = vsVersions.First();
MSBuildLocator.RegisterInstance(vsVersion);

See - https://docs.microsoft.com/ru-ru/visualstudio/msbuild/updating-an-existing-application?view=vs-2019#use-microsoftbuildlocator

@BjarkeMeier
Copy link

@AlexeiScherbakov , thanks a lot. It works. This issue should be closed with your answer as the solution.

@AlexeiScherbakov
Copy link

AlexeiScherbakov commented Nov 15, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants