Skip to content

Commit 797ee5c

Browse files
authored
Add MSBuildProjectDirectory fallback to ProjectDir resolution (#5146)
1 parent f8bb51a commit 797ee5c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>14.3.0</VersionPrefix>
3+
<VersionPrefix>14.3.1</VersionPrefix>
44

55
<Authors>Rico Suter</Authors>
66
<Copyright>Copyright © Rico Suter, 2023</Copyright>

src/NSwag.Commands/Commands/Generation/AspNetCore/ProjectMetadata.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ public static async Task<ProjectMetadata> GetProjectMetadata(
8383

8484
var args = CreateMsBuildArguments(file, framework, configuration, runtime, noBuild, outputPath);
8585

86-
var metadata = await TryReadingUsingGetProperties(args, file, noBuild) ?? await ReadUsingMsBuildTargets(args, file, buildExtensionsDir, console);
86+
var metadata = await TryReadingUsingGetProperties(args, file, noBuild);
87+
if (metadata == null || string.IsNullOrWhiteSpace(metadata[nameof(ProjectDir)]))
88+
{
89+
metadata = await ReadUsingMsBuildTargets(args, file, buildExtensionsDir, console);
90+
}
8791

8892
var platformTarget = metadata[nameof(PlatformTarget)];
8993
if (platformTarget.Length == 0)
@@ -225,7 +229,8 @@ private static async Task<Dictionary<string, string>> TryReadingUsingGetProperti
225229
nameof(ProjectDir),
226230
nameof(ProjectRuntimeConfigFilePath),
227231
nameof(TargetFileName),
228-
nameof(TargetFrameworkIdentifier)
232+
nameof(TargetFrameworkIdentifier),
233+
"MSBuildProjectDirectory",
229234
};
230235

231236
try
@@ -251,6 +256,12 @@ private static async Task<Dictionary<string, string>> TryReadingUsingGetProperti
251256
.EnumerateObject()
252257
.ToDictionary(x => x.Name, x => x.Value.ToString().Trim());
253258

259+
// depending on the project type or MSBuild evaluation process, the ProjectDir property may not be set
260+
if (string.IsNullOrWhiteSpace(metadata[nameof(ProjectDir)]))
261+
{
262+
metadata[nameof(ProjectDir)] = metadata["MSBuildProjectDirectory"];
263+
}
264+
254265
return metadata;
255266
}
256267
}

0 commit comments

Comments
 (0)