Skip to content

Commit 7eef9d8

Browse files
lifenglLifeng Lu
andauthored
Unblock JavaScript projects to load (#9708)
* Unblock JavaScript projects to load The launch setting provider is loaded in JavaScript earlier than configured project is loaded, due to how it adds the capability (through its factory). It leads GetLaunchSettingsFilePathNoCacheAsync called before active configured project is loaded and leads NFE. This PR is to wait configured project to load before accessing project properties. * Update unit test Moq. * Add some comments to the code changed. --------- Co-authored-by: Lifeng Lu <[email protected]>
1 parent 397371c commit 7eef9d8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,14 @@ internal async Task<string> GetLaunchSettingsFilePathNoCacheAsync()
873873
// even though it can change over the lifetime of the project. We should fix this and convert to using dataflow
874874
// see: https://github.com/dotnet/project-system/issues/2316.
875875

876+
if (_project.Services.ActiveConfiguredProjectProvider is IActiveConfiguredProjectProvider activeConfiguredProjectProvider &&
877+
activeConfiguredProjectProvider.ActiveConfiguredProject is null)
878+
{
879+
// in a project system the LauchProfile is turned on through project factory, the provider can be initialized before configuration is loaded.
880+
// Because _projectProperties is depending on the active configured project, it will end up with NFE failure.
881+
await activeConfiguredProjectProvider.ActiveConfiguredProjectBlock.ReceiveAsync(_project.Services.ProjectAsynchronousTasks?.UnloadCancellationToken ?? CancellationToken.None);
882+
}
883+
876884
// Default to the project directory if we're not able to get the AppDesigner folder.
877885
string folder = _commonProjectServices.Project.GetProjectDirectory();
878886

tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/ProjectSystem/Debug/LaunchSettingsProviderTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ internal static LaunchSettingsUnderTest GetLaunchSettingsProvider(IFileSystem? f
2222

2323
var projectProperties = ProjectPropertiesFactory.Create(AppDesigner.SchemaName, AppDesigner.FolderNameProperty, appDesignerFolder);
2424
var activeConfigurationProjectProperties = IActiveConfiguredValueFactory.ImplementValue<ProjectProperties?>(() => projectProperties);
25-
var project = UnconfiguredProjectFactory.Create(fullPath: @"c:\test\Project1\Project1.csproj");
25+
var configuredProject = ConfiguredProjectFactory.Create();
26+
var project = UnconfiguredProjectFactory.Create(fullPath: @"c:\test\Project1\Project1.csproj", configuredProject: configuredProject);
2627
var properties = ProjectPropertiesFactory.Create(project, [debuggerData]);
2728
var threadingService = IProjectThreadingServiceFactory.Create();
2829
var commonServices = IUnconfiguredProjectCommonServicesFactory.Create(project, threadingService, null, properties);

0 commit comments

Comments
 (0)