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

MSBuildWorkspace: Unable to build hello world .netstandard2.0 class library anymore #52293

Open
ceztko opened this issue Mar 31, 2021 · 10 comments
Assignees
Milestone

Comments

@ceztko
Copy link

ceztko commented Mar 31, 2021

NOTE: I'm duplicating the issue from MSBuild tracker since I noticed the actual development of MSBuildWorkspace happens in roslyn repository.

Issue Description

Using MSBuild.Locator, Workspaces.MSBuild and the Roslyn infrastructure I'm unable to compile an hello world netstandard2.0 class library. The same library compile just fine when targeting .Net framework 4.5.2. I noticed the issue after I installed Visual Studio 16.8. Some releases before the same scenario was working.

Steps to Reproduce

  1. Unpack the following test project:
    TestMSBuildWorkspaceCompilation.zip [UPDATE: Improved layout of the project]

  2. Open TestMSBuildWorkspaceCompilation.sln;

  3. Compile and run TestMSBuildWorkspaceCompilation project. When trying to compile the netstandard2.0 project an exception should trigger and compilation errors are printed. More explanations are in the code there.

Expected Behavior

No compilation errors should the issued when compiling the project targeting netstandard2.0.

Actual Behavior

A bunch of errors are printed, as the build system is unable to load the netstandard2.0 base library when compiling the project.

TestClassLibrary\obj\Debug\netstandard2.0\.NETStandard,Version=v2.0.AssemblyAttributes.cs[82..88)), CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?)
TestMSBuildWorkspaceCompilation\TestClassLibrary\obj\Debug\netstandard2.0\TestClassLibrary.AssemblyInfo.cs[421..427)), CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
TestMSBuildWorkspaceCompilation\TestClassLibrary\obj\Debug\netstandard2.0\TestClassLibrary.AssemblyInfo.cs[497..503)), CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
[...]

Analysis

I'm currently using VS 16.9.2 but the same scenario was working some releases before 16.8.

Versions & Configurations

Microsoft.CodeAnalysis.*Workspaces* 3.9
Microsoft.Build.Locator 1.4.1
VisualStudio 16.9.2
.NET SDK 5.0.201
msbuild 16.9.0.11203

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Mar 31, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@jinujoseph jinujoseph added Bug IDE-MSBuildWorkspace MSBuildWorkspace and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Mar 31, 2021
@jinujoseph jinujoseph added this to the 16.10 milestone Mar 31, 2021
@JoeRobich
Copy link
Member

@ceztko If you run dotnet restore against the net standard project first, does it open as expected?

@ceztko
Copy link
Author

ceztko commented Mar 31, 2021

@JoeRobich Yes, it does. I updated the layout of the test project so you can run dotnet restore both against the project or the solution containing the project and it will workaround the issue with MSBuildWorkspace and the programmatic compilation. I have the feeling I didn't need this in the past. Should I assume this is indeed a bug or it's the expected behavior? Can I actually run a dotnet restore operation programmatically?

@ceztko
Copy link
Author

ceztko commented Apr 2, 2021

Switching the library from netstandard2.0 to netcoreapp3.1 silences the issue, but of course it's not generally a valid workaround. It can help in some scenarios, though. I see the target for the fix is 16.10. Any chance the fix will be backported to 16.9 (which should be the servicing baseline for VS)?

@jmarolf
Copy link
Contributor

jmarolf commented Apr 2, 2021

@ceztko MSBuildWorkspace is just an API that ships as a nuget package I do not understand what porting it to 16.9 would mean

@ceztko
Copy link
Author

ceztko commented Apr 3, 2021

@jmarolf ah, sorry. I read "Milestone 16.10" above and I thought the fix was related to some infrastructure package that is usually deployed together with VS (for example this is the case for msbuild). Ok, I will just wait for the next refresh of Microsoft.CodeAnalysis.* packages.

@jinujoseph jinujoseph modified the milestones: 16.10, 17.0 Jun 1, 2021
@jmarolf jmarolf modified the milestones: 17.0, 17.1 Sep 8, 2021
@jmarolf jmarolf modified the milestones: 17.1, 17.2 Jan 10, 2022
@jmarolf jmarolf modified the milestones: 17.2, 17.3 Mar 18, 2022
@ceztko
Copy link
Author

ceztko commented Aug 24, 2022

Since the fix for this issue was delayed multiple times, is there a realistic milestone now?

@JoeRobich
Copy link
Member

@ceztko I tried your example and reproduced your issue. I then ran dotnet restore against the netstandard project and reran your tool. This time it completed with no errors.

I believe this PR #61391 would help resolve your issue as you could additionally request a restore when you are loading the project into the workspace.

@ceztko
Copy link
Author

ceztko commented Aug 25, 2022

@JoeRobich thanks, I hope the PR gets merged soon, and that there are no conflict of responsibility for the handling of this issue. Also, may I suggest to put the compilation of few simple projects (such as the ones I attached here) with MSBuildWorkspace under unit testing? I noticed such use case to be quite fragile and breaking easily, the last one in #58286 / microsoft/MSBuildLocator#176 which you are also following.

@arunchndr arunchndr modified the milestones: 17.3, 17.6 P2 Jan 17, 2023
@ceztko
Copy link
Author

ceztko commented Aug 10, 2023

Any update on this issue? Was the reload/restore API introduced eventually?

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

Successfully merging a pull request may close this issue.

5 participants