-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Disallow applying updates to FBA MSBuildWorkspace #84722
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -957,12 +957,15 @@ public static class Util | |
| [ConditionalFact(typeof(DotNetSdkMSBuildInstalled))] | ||
| [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] | ||
| [Trait(Traits.Feature, Traits.Features.NetCore)] | ||
| [WorkItem("https://github.com/dotnet/roslyn/issues/84721")] | ||
| public async Task TestOpenProject_FileBasedApp_AddProjectReference() | ||
| { | ||
| var programSource = """ | ||
| Util.M(); | ||
| """; | ||
|
|
||
| CreateFiles(new FileSet( | ||
| ("Program.cs", """ | ||
| Util.M(); | ||
| """), | ||
| ("Program.cs", programSource), | ||
| ("Util.cs", """ | ||
| #:property OutputType=Library | ||
| public static class Util | ||
|
|
@@ -978,8 +981,14 @@ public static class Util | |
| Assert.Equal(["Program"], workspace.CurrentSolution.Projects.Select(p => p.Name).Order()); | ||
| Assert.Empty(programProject.ProjectReferences); | ||
|
|
||
| var diag = Assert.Single((await programProject.GetCompilationAsync()).GetDiagnostics().Where(d => d.Severity == DiagnosticSeverity.Error && d.GetMessage().Contains("Util"))); | ||
| Assert.Equal("CS0103", diag.Id); // The name 'Util' does not exist in the current context | ||
| var expectedDiagnostics = new[] | ||
| { | ||
| // (1,1): error CS0103: The name 'Util' does not exist in the current context | ||
| // Util.M(); | ||
| Diagnostic(103, "Util").WithArguments("Util").WithLocation(1, 1), | ||
| }; | ||
|
|
||
| (await GetDiagnosticsAsync(programProject)).Verify(expectedDiagnostics); | ||
|
|
||
| var utilProject = await workspace.OpenProjectAsync(GetSolutionFileName("Util.cs")); | ||
|
|
||
|
|
@@ -992,14 +1001,34 @@ public static class Util | |
| var solution = programProject.AddProjectReference(new ProjectReference(utilProject.Id)).Solution; | ||
| Assert.True(workspace.TryApplyChanges(solution)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's kinda strange to me that this isn't returning false and we're not throwing an exception, but I guess that's the pattern this code uses generally....strange. If you have to touch this PR for any other reason consider adding a comment here, otherwise let it be.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree this is weird but also seems by design. Per its doc comment (and implementation), TryApplyChanges
|
||
|
|
||
|
jjonescz marked this conversation as resolved.
|
||
| Assert.Empty(workspace.Diagnostics); | ||
| Assert.Collection(workspace.Diagnostics, | ||
| d => | ||
| { | ||
| Assert.Equal(WorkspaceDiagnosticKind.Failure, d.Kind); | ||
| Assert.Contains(string.Format(WorkspaceMSBuildResources.Applying_updates_to_file_based_apps_is_not_supported_0, Path.Combine(SolutionDirectory.Path, "Program.cs")), d.Message); | ||
| }); | ||
|
|
||
| Assert.Equal(["Program", "Util"], workspace.CurrentSolution.Projects.Select(p => p.Name).Order()); | ||
|
|
||
| var programText = await programProject.Documents.Single(d => d.Name == "Program.cs").GetTextAsync(); | ||
| AssertEx.Equal(programSource, programText.ToString()); | ||
|
|
||
| Assert.Collection(Directory.EnumerateFileSystemEntries(SolutionDirectory.Path).Order(), | ||
| entry => Assert.Equal(Path.Combine(SolutionDirectory.Path, ".packages"), entry), | ||
| entry => Assert.Equal(Path.Combine(SolutionDirectory.Path, "Program.cs"), entry), | ||
| entry => Assert.Equal(Path.Combine(SolutionDirectory.Path, "Util.cs"), entry)); | ||
|
|
||
| programProject = workspace.CurrentSolution.Projects.Single(p => p.Name == "Program"); | ||
| var projRef = Assert.Single(programProject.ProjectReferences); | ||
| Assert.Equal(projRef.ProjectId, workspace.CurrentSolution.Projects.Single(p => p.Name == "Util").Id); | ||
| Assert.Empty(programProject.ProjectReferences); | ||
|
|
||
| (await GetDiagnosticsAsync(programProject)).Verify(expectedDiagnostics); | ||
|
|
||
| Assert.Empty((await programProject.GetCompilationAsync()).GetDiagnostics().Where(d => d.Severity == DiagnosticSeverity.Error && d.GetMessage().Contains("Util"))); | ||
| static async Task<IEnumerable<Diagnostic>> GetDiagnosticsAsync(Project project) | ||
| { | ||
| return (await project.GetCompilationAsync()) | ||
| .GetDiagnostics() | ||
| .Where(d => d.Severity == DiagnosticSeverity.Error && d.GetMessage().Contains("Util")); | ||
| } | ||
| } | ||
|
|
||
| [ConditionalFact(typeof(DotNetSdkMSBuildInstalled))] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: feels reasonable to also assert we did not write a '.cs.csproj' file to disk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm asserting that below with