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

Failure to load dotnet/runtime project or solution #49384

Closed
carlossanlop opened this issue Nov 15, 2020 · 5 comments
Closed

Failure to load dotnet/runtime project or solution #49384

carlossanlop opened this issue Nov 15, 2020 · 5 comments
Labels
untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@carlossanlop
Copy link
Member

carlossanlop commented Nov 15, 2020

When I try to load a src project from the dotnet/runtime repo, it comes back without any documents, and the compilation has no symbols.

I found this message among the workspace diagnostic errors:

Msbuild failed when processing the file
'D:\runtime\src\libraries\System.IO.Compression\src\System.IO.Compression.csproj' with message:
The SDK 'Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk' specified could not be found.
D:\runtime\src\libraries\Directory.Build.props

I tried adding the nuget package of that SDK into my project. I found it in my the folder C:\Users\carlos\.nuget\packages. It showed up there after building the dotnet/runtime repo.

But adding that nuget package to my project causes this error to show up when attempting to build the project:

The "ChooseBestP2PTargetFrameworkTask" task was not given a value for the required parameter "RuntimeGraph".

It comes from C:\Users\carlos\.nuget\packages\microsoft.dotnet.build.tasks.targetframework.sdk\6.0.0-beta.20554.1\build\Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk.targets line 79.

Here is a code snippet that repros the problem:

// Path can be a csproj or a sln
// Example of sln: @"D:\runtime\src\libraries\System.IO.Compression\System.IO.Compression.sln"
// Example of csproj: @"D:\runtime\src\libraries\System.IO.Compression\src\System.IO.Compression.csproj"
void Load(string path)
{
    MSBuildLocator.RegisterDefaults();
    MSBuildWorkspace workspace = MSBuildWorkspace.Create();

    Project? project = null;
    if (path.EndsWith("sln"))
    {
        Solution solution = workspace.OpenSolutionAsync(path).Result;
        foreach (Project p in solution.Projects)
        {
            string dirName = Path.GetDirectoryName(p.FilePath);
            if (p.SupportsCompilation && // This is true
                p.HasDocuments && // This is always false, probably related to the diagnostic error, see below
                dirName.EndsWith("src")) // Skip ref or tests folders
            {
                project = p;
                break;
            }
        }
    }
    else if (path.EndsWith("csproj"))
    {
        project = workspace.OpenProjectAsync(path).Result;
    }

    if (project == null)
    {
        ImmutableList<WorkspaceDiagnostic> diagnostics = workspace.Diagnostics;
        if (diagnostics.Any())
        {
            foreach (var diagnostic in diagnostics)
            {
                Log.Error(diagnostic.Message);
                // Msbuild failed when processing the file
                // 'D:\runtime\src\libraries\System.IO.Compression\src\System.IO.Compression.csproj' with message:
                // The SDK 'Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk' specified could not be found.
                // D:\runtime\src\libraries\Directory.Build.props
            }
            Log.Error("Found diagnostic errors. Exiting.");
            Environment.Exit(0);
        }
    }
    else
    {
        // This works if I pass a csproj directly, but it's useless since it has no symbols anyway
        Compilation? compilation = project.GetCompilationAsync().Result;
    }
}

cc @safern @jaredpar

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 15, 2020
@Dotnet-GitSync-Bot
Copy link
Collaborator

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.

@safern
Copy link
Member

safern commented Nov 15, 2020

It would be interesting to get a binlog. I don't know how the MSBuild workplace evaluates projects and how it interacts with the Roslyn compilation.

Note that the SDK that is not finding is an SDK we have for our custom target framework support that lives in arcade.

cc: @rainersigwald

@rainersigwald
Copy link
Member

This is probably a duplicate of microsoft/MSBuildLocator#88.

@carlossanlop
Copy link
Member Author

@rainersigwald the linked issue has been open since April, but has not yet been fixed or investigated. This is currently blocking us, the runtime team, from being able to advance in a project we are working on. Would you mind taking a closer look?

@carlossanlop
Copy link
Member Author

@safern and I took a deeper look at this, and we solved it with a combination of:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

4 participants