@@ -13,28 +13,28 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Retargeting;
13
13
[ Order ( Order . Default ) ]
14
14
internal sealed partial class ProjectRetargetHandler : IProjectRetargetHandler , IDisposable
15
15
{
16
- private readonly UnconfiguredProject _unconfiguredProject ;
17
16
private readonly Lazy < IDotNetReleasesProvider > _releasesProvider ;
18
17
private readonly IFileSystem _fileSystem ;
19
18
private readonly IProjectThreadingService _projectThreadingService ;
20
19
private readonly IVsService < SVsTrackProjectRetargeting , IVsTrackProjectRetargeting2 > _projectRetargetingService ;
20
+ private readonly IVsService < SVsSolution , IVsSolution > _solutionService ;
21
21
22
22
private Guid _currentSdkDescriptionId = Guid . Empty ;
23
23
private Guid _sdkRetargetId = Guid . Empty ;
24
24
25
25
[ ImportingConstructor ]
26
26
public ProjectRetargetHandler (
27
- UnconfiguredProject unconfiguredProject ,
28
27
Lazy < IDotNetReleasesProvider > releasesProvider ,
29
28
IFileSystem fileSystem ,
30
29
IProjectThreadingService projectThreadingService ,
31
- IVsService < SVsTrackProjectRetargeting , IVsTrackProjectRetargeting2 > projectRetargetingService )
30
+ IVsService < SVsTrackProjectRetargeting , IVsTrackProjectRetargeting2 > projectRetargetingService ,
31
+ IVsService < SVsSolution , IVsSolution > solutionService )
32
32
{
33
- _unconfiguredProject = unconfiguredProject ;
34
33
_releasesProvider = releasesProvider ;
35
34
_fileSystem = fileSystem ;
36
35
_projectThreadingService = projectThreadingService ;
37
36
_projectRetargetingService = projectRetargetingService ;
37
+ _solutionService = solutionService ;
38
38
}
39
39
40
40
public Task < IProjectTargetChange ? > CheckForRetargetAsync ( RetargetCheckOptions options )
@@ -133,11 +133,11 @@ public Task RetargetAsync(TextWriter outputLogger, RetargetOptions options, IPro
133
133
134
134
private async Task < string ? > GetSdkVersionForProjectAsync ( )
135
135
{
136
- string projectDirectory = _unconfiguredProject . GetProjectDirectory ( ) ;
136
+ string ? solutionDirectory = await GetSolutionDirectoryAsync ( ) ;
137
137
138
- if ( ! string . IsNullOrEmpty ( projectDirectory ) )
138
+ if ( ! string . IsNullOrEmpty ( solutionDirectory ) )
139
139
{
140
- string ? globalJsonPath = FindGlobalJsonPath ( projectDirectory ) ;
140
+ string ? globalJsonPath = FindGlobalJsonPath ( solutionDirectory ! ) ;
141
141
if ( globalJsonPath is not null )
142
142
{
143
143
try
@@ -159,6 +159,22 @@ public Task RetargetAsync(TextWriter outputLogger, RetargetOptions options, IPro
159
159
return null ;
160
160
}
161
161
162
+ private async Task < string ? > GetSolutionDirectoryAsync ( )
163
+ {
164
+ IVsSolution ? solution = await _solutionService . GetValueOrNullAsync ( ) ;
165
+
166
+ if ( solution is not null )
167
+ {
168
+ int hr = solution . GetSolutionInfo ( out string solutionDirectory , out string _ , out string _ ) ;
169
+ if ( hr == HResult . OK && ! string . IsNullOrEmpty ( solutionDirectory ) )
170
+ {
171
+ return solutionDirectory ;
172
+ }
173
+ }
174
+
175
+ return null ;
176
+ }
177
+
162
178
public void Dispose ( )
163
179
{
164
180
if ( _currentSdkDescriptionId != Guid . Empty || _sdkRetargetId != Guid . Empty )
0 commit comments