@@ -17,6 +17,7 @@ namespace Microsoft.Tools.ServiceModel.Svcutil
17
17
{
18
18
internal class MSBuildProj : IDisposable
19
19
{
20
+ private const string DirBuildProps = "Directory.Build.props" ;
20
21
private bool _isSaved ;
21
22
private bool _ownsDirectory ;
22
23
private readonly ProjectPropertyResolver _propertyResolver ;
@@ -198,10 +199,15 @@ public static async Task<MSBuildProj> ParseAsync(string projectText, string proj
198
199
if ( targetFrameworkElements . Count ( ) > 0 )
199
200
{
200
201
// If property is specified more than once, MSBuild will resolve it by overwriting it with the last value.
201
- var targetFramework = targetFrameworkElements . Last ( ) . Value . Trim ( ) . ToLowerInvariant ( ) ;
202
+ var targetFramework = targetFrameworkElements . Last ( ) . Value . Trim ( ) ;
202
203
if ( ! string . IsNullOrWhiteSpace ( targetFramework ) )
203
204
{
204
- if ( TargetFrameworkHelper . IsSupportedFramework ( targetFramework , out FrameworkInfo fxInfo ) )
205
+ if ( targetFramework . ToString ( ) . StartsWith ( "$" ) )
206
+ {
207
+ targetFramework = GetValueFromDirBuildProps ( targetFramework , msbuildProj . DirectoryPath ) ;
208
+ }
209
+
210
+ if ( TargetFrameworkHelper . IsSupportedFramework ( targetFramework , out FrameworkInfo fxInfo ) )
205
211
{
206
212
msbuildProj . _targetFrameworks . Add ( targetFramework ) ;
207
213
}
@@ -215,6 +221,11 @@ public static async Task<MSBuildProj> ParseAsync(string projectText, string proj
215
221
if ( targetFrameworksElements . Count ( ) > 0 )
216
222
{
217
223
var targetFrameworks = targetFrameworksElements . Last ( ) . Value ;
224
+ if ( targetFrameworks . ToString ( ) . StartsWith ( "$" ) )
225
+ {
226
+ targetFrameworks = GetValueFromDirBuildProps ( targetFrameworks , msbuildProj . DirectoryPath ) ;
227
+ }
228
+
218
229
foreach ( var targetFx in targetFrameworks . Split ( new char [ ] { ';' } , StringSplitOptions . RemoveEmptyEntries ) . Select ( p => p . Trim ( ) ) )
219
230
{
220
231
if ( ! string . IsNullOrWhiteSpace ( targetFx ) )
@@ -415,6 +426,27 @@ public static async Task<MSBuildProj> DotNetNewAsync(string fullPath, ILogger lo
415
426
return project ;
416
427
}
417
428
429
+ private static string GetValueFromDirBuildProps ( string elementStr , string dirPath )
430
+ {
431
+ try
432
+ {
433
+ //elementStr format: $(ElementName)
434
+ elementStr = elementStr . Substring ( 2 ) . TrimEnd ( ')' ) ;
435
+ string filePath = Path . Combine ( dirPath , DirBuildProps ) ;
436
+ XDocument doc = XDocument . Load ( filePath ) ;
437
+ var ele = doc . Root ? . Descendants ( elementStr ) . FirstOrDefault ( ) ;
438
+ if ( ele != null )
439
+ {
440
+ return ele . Value ;
441
+ }
442
+ }
443
+ catch
444
+ {
445
+ }
446
+
447
+ return "" ;
448
+ }
449
+
418
450
private static IEnumerable < XElement > GetGroupValues ( XElement projectElement , string group , bool createOnMissing = false )
419
451
{
420
452
// XElement.Elements() always returns a collection, no need to check for null.
0 commit comments