diff --git a/src/Workspaces/MSBuild/Core/MSBuild/MSBuildWorkspace.cs b/src/Workspaces/MSBuild/Core/MSBuild/MSBuildWorkspace.cs index 6069b3c46d575..7030a548ef575 100644 --- a/src/Workspaces/MSBuild/Core/MSBuild/MSBuildWorkspace.cs +++ b/src/Workspaces/MSBuild/Core/MSBuild/MSBuildWorkspace.cs @@ -357,27 +357,18 @@ protected override void ApplyProjectChanges(ProjectChanges projectChanges) if (_loader.ProjectFileExtensionRegistry.TryGetLanguageNameFromProjectPath(projectPath, DiagnosticReportingMode.Log, out var languageName, out var isFileBasedApp)) { + if (isFileBasedApp) + { + Reporter.Report(new ProjectDiagnostic(WorkspaceDiagnosticKind.Failure, + string.Format(WorkspaceMSBuildResources.Applying_updates_to_file_based_apps_is_not_supported_0, projectPath), + projectChanges.ProjectId)); + return; + } + try { - var preferredBuildHostKind = isFileBasedApp - ? BuildHostProcessKind.NetCore - : BuildHostProcessManager.GetKindForProject(projectPath); - var (buildHost, _) = _applyChangesBuildHostProcessManager.GetBuildHostWithFallbackAsync(preferredBuildHostKind, projectPath, CancellationToken.None).Result; - - if (isFileBasedApp) - { - var fileBasedProgramService = this.Services.GetRequiredService(); - _applyChangesProjectFile = FileBasedProgramsProjectLoader.LoadFileBasedAppProjectAsync( - buildHost, - fileBasedProgramService, - projectPath, - (error) => Reporter.Report(new WorkspaceDiagnostic(WorkspaceDiagnosticKind.Failure, error)), - CancellationToken.None).Result; - } - else - { - _applyChangesProjectFile = buildHost.LoadProjectFileAsync(projectPath, languageName, CancellationToken.None).Result; - } + var buildHost = _applyChangesBuildHostProcessManager.GetBuildHostWithFallbackAsync(projectPath, CancellationToken.None).Result; + _applyChangesProjectFile = buildHost.LoadProjectFileAsync(projectPath, languageName, CancellationToken.None).Result; } catch (IOException exception) { diff --git a/src/Workspaces/MSBuild/Core/WorkspaceMSBuildResources.resx b/src/Workspaces/MSBuild/Core/WorkspaceMSBuildResources.resx index a4f7ffbd318fe..addd41b0c51e3 100644 --- a/src/Workspaces/MSBuild/Core/WorkspaceMSBuildResources.resx +++ b/src/Workspaces/MSBuild/Core/WorkspaceMSBuildResources.resx @@ -174,4 +174,8 @@ The build host could not be found at '{0}' + + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + \ No newline at end of file diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.cs.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.cs.xlf index 360c73fdeaba5..caef775926e80 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.cs.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.cs.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' Nepovedlo se načíst řešení: {0} diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.de.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.de.xlf index 8ac125c241f78..cd9dddd725d69 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.de.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.de.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' Fehler beim Laden der Lösung: „{0}“ diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.es.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.es.xlf index 6ad4ecd111362..d9cc81b352e89 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.es.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.es.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' Error al cargar la solución: “{0}” diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.fr.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.fr.xlf index 82c915ca6a775..71016c6b5f48e 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.fr.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.fr.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' Nous n’avons pas pu charger la solution : « {0} » diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.it.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.it.xlf index 9a59291b506e6..c967552319356 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.it.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.it.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' Non è possibile caricare la soluzione: '{0}' diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ja.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ja.xlf index 5053d5970ffe9..2d30821d9ad43 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ja.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ja.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' ソリューション: '{0}' を読み込むことができませんでした diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ko.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ko.xlf index 83a651cc28beb..df8156f7b7082 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ko.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ko.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' 솔루션 로드 실패: ’{0}’ diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.pl.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.pl.xlf index 533dadba16277..8302fb24a5f90 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.pl.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.pl.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' Nie można załadować rozwiązania: „{0}” diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.pt-BR.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.pt-BR.xlf index 74bbc6937ac7e..f5c3b8e7ee63a 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.pt-BR.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.pt-BR.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' Falha ao carregar a solução: "{0}" diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ru.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ru.xlf index 401b5a33f0cd5..d1f515e6d9afa 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ru.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.ru.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' Не удалось загрузить решение: "{0}" diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.tr.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.tr.xlf index e73313510bf04..c0d7ac747d99b 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.tr.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.tr.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' Çözüm yüklenemedi: '{0}' diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.zh-Hans.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.zh-Hans.xlf index d6d323207f7ad..a5ae57fc35ff7 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.zh-Hans.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.zh-Hans.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' 无法加载解决方案:“{0}” diff --git a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.zh-Hant.xlf b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.zh-Hant.xlf index f8d9f2451fe3d..a1e551708bce9 100644 --- a/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.zh-Hant.xlf +++ b/src/Workspaces/MSBuild/Core/xlf/WorkspaceMSBuildResources.zh-Hant.xlf @@ -2,6 +2,11 @@ + + Applying updates to file-based apps is not supported: {0} + Applying updates to file-based apps is not supported: {0} + {0} is path to the file-based app + Failed to load solution: '{0}' 無法載入解決方案: '{0}' diff --git a/src/Workspaces/MSBuild/Test/NetCoreTests.cs b/src/Workspaces/MSBuild/Test/NetCoreTests.cs index 15547c981a035..cec8dfc516516 100644 --- a/src/Workspaces/MSBuild/Test/NetCoreTests.cs +++ b/src/Workspaces/MSBuild/Test/NetCoreTests.cs @@ -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)); - 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> GetDiagnosticsAsync(Project project) + { + return (await project.GetCompilationAsync()) + .GetDiagnostics() + .Where(d => d.Severity == DiagnosticSeverity.Error && d.GetMessage().Contains("Util")); + } } [ConditionalFact(typeof(DotNetSdkMSBuildInstalled))]