-
Notifications
You must be signed in to change notification settings - Fork 4k
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 doesn't raise warnings or errors if the app is targeting too low of a version of Roslyn #69578
Comments
I'm having issues with GetCompilationAsync with not running the razor generator as well. I have a blazor application. Scanning files with a code behind with .razor.cs extension. I have the following code using var workspace = MSBuildWorkspace.Create(
new Dictionary<string, string>
{
{ "EnableNETAnalyzers", "true" },
});
workspace.LoadMetadataForReferencedProjects = true;
var solution = await workspace.OpenSolutionAsync(solutionFile.FullName);
var project = solution.Projects.FirstOrDefault(x => x.Name?.EndsWith(projectName, StringComparison.OrdinalIgnoreCase) ?? false);
var compilation = await project.GetCompilationAsync();
foreach (var document in project.Documents.Where(x => x.FilePath?.EndsWith("*.razor.cs", StringComparison.OrdinalIgnoreCase) == true))
{
var syntaxTree = await document.GetSyntaxTreeAsync();
if (syntaxTree is null)
{
continue;
}
var rootNode = await document.GetSyntaxRootAsync();
if (rootNode is null)
{
continue;
}
var semanticModel = compilation.GetSemanticModel(syntaxTree);
var syntaxDeclaration = rootNode.DescendantNodesAndSelf().OfType<ClassDeclarationSyntax>().First();
var symbol = semanticModel.GetDeclaredSymbol(syntaxDeclaration);
var isComponentType = symbol.AllInterfaces.Any(x => x.Name.Equals("IComponent"));
} My expectation is for a interface called IComponent to exist in a blazor application for razor backed CS partial files, and the source generator to have run. In 7.0.3 this is the outcome, in 7.0.4 I get no interfaces in the |
@jasonmalinowski @chsienki I assume you two are the experts here, not sure if this is a deliberate change, but it seems odd that multiple people have started hitting it today. |
We had another report of 7.0.400 breaking things due to the NuGet.Frameworks version problem, so that could be it here. That only shipped last week I think. @glennawatson: if you add an event handler for MSBuildWorkspace.WorkspaceFailed, is that being raised with an error while you call OpenSolutionAsync? |
What version of Razor in I was able to repro using the above code when running on |
@chsienki using 4.6.0. Will try the prerelease version today. |
@jasonmalinowski As an aside, we (the compiler side) are raising an |
@jasonmalinowski i didn't see anything unusual in the workspace failed events. |
@chsienki Oh ouch, that's not good; we should probably raise that somwhere. Also:
We shipped 17.7 last week, looks like we're still working on shipping packages though. |
I can also confirm that targeting 4.7.0-2.final version of |
The 4.7.0 packages should be out soon, there's a bit of a hangup due to some dependency issues we're having to sort out.
Agreed; let's retitle this bug to reflect that fact! |
@jasonmalinowski The very same project builds correctly when the build is performed from Visual Studio (Community 2022 17.8.0 Preview 2.0). The error message is the following: The version of |
@antonioaversa Yep, that's something we're working on fixing. Which TFMs was your app that was using MSBuildWorkspace targeting? |
@jasonmalinowski |
So I think this bug can now be closed since #61454 is closed too; I don't see anything that was specific in this otherwise that isn't fixed by OOP builds? |
Closing this now that the 4.9.0-2.final packages are out; if there's still issues people are running into it'd be best for us to have a new issue since there's a lot of different things being conflated here. |
On .NET SDK 7.0.307 I was able to use GetCompilationAsync to compile razor projects, however after updating to .NET SDK 7.0.4, it does not work anymore.
The issue might be related to this Roslyn issue, but I am not sure.
As I have described on that issue after updating to v7.0.4 a workaround needs to be applied to be able to load the project successfully. After loading the project successfully, the compilation succeeds too, but the razor-generated files cannot be seen in the syntax trees.
The text was updated successfully, but these errors were encountered: