@@ -244,32 +244,39 @@ private bool ExecuteGenerateTemporaryTargetAssemblyWithPackageReferenceSupport()
244
244
RemoveItemsByName ( xmlProjectDoc , MARKUPRESOURCENAME ) ;
245
245
RemoveItemsByName ( xmlProjectDoc , RESOURCENAME ) ;
246
246
247
+ // Replace the Reference Item list with ReferencePath
248
+ RemoveItemsByName ( xmlProjectDoc , REFERENCETYPENAME ) ;
249
+ AddNewItems ( xmlProjectDoc , ReferencePathTypeName , ReferencePath ) ;
250
+
251
+ // Add GeneratedCodeFiles to Compile item list.
252
+ AddNewItems ( xmlProjectDoc , CompileTypeName , GeneratedCodeFiles ) ;
253
+
254
+ // Replace implicit SDK imports with explicit SDK imports
255
+ ReplaceImplicitImports ( xmlProjectDoc ) ;
256
+
247
257
// Add properties required for temporary assembly compilation
248
258
var properties = new List < ( string PropertyName , string PropertyValue ) >
249
259
{
250
260
( nameof ( AssemblyName ) , AssemblyName ) ,
251
261
( nameof ( IntermediateOutputPath ) , IntermediateOutputPath ) ,
252
- ( "AppendTargetFrameworkToOutputPath" , "false" ) ,
262
+ ( nameof ( BaseIntermediateOutputPath ) , BaseIntermediateOutputPath ) ,
253
263
( "_TargetAssemblyProjectName" , Path . GetFileNameWithoutExtension ( CurrentProject ) ) ,
254
- ( nameof ( Analyzers ) , Analyzers )
264
+ ( nameof ( Analyzers ) , Analyzers )
255
265
} ;
256
266
257
267
AddNewProperties ( xmlProjectDoc , properties ) ;
258
268
259
- // Replace the Reference Item list with ReferencePath
260
- RemoveItemsByName ( xmlProjectDoc , REFERENCETYPENAME ) ;
261
- AddNewItems ( xmlProjectDoc , ReferencePathTypeName , ReferencePath ) ;
262
-
263
- // Add GeneratedCodeFiles to Compile item list.
264
- AddNewItems ( xmlProjectDoc , CompileTypeName , GeneratedCodeFiles ) ;
265
-
266
269
// Save the xmlDocument content into the temporary project file.
267
270
xmlProjectDoc . Save ( TemporaryTargetAssemblyProjectName ) ;
268
271
272
+ // Disable conflicting Arcade SDK workaround that imports NuGet props/targets
273
+ Hashtable globalProperties = new Hashtable ( 1 ) ;
274
+ globalProperties [ "_WpfTempProjectNuGetFilePathNoExt" ] = "" ;
275
+
269
276
//
270
277
// Compile the temporary target assembly project
271
278
//
272
- retValue = BuildEngine . BuildProjectFile ( TemporaryTargetAssemblyProjectName , new string [ ] { CompileTargetName } , null , null ) ;
279
+ retValue = BuildEngine . BuildProjectFile ( TemporaryTargetAssemblyProjectName , new string [ ] { CompileTargetName } , globalProperties , null ) ;
273
280
274
281
// Delete the temporary project file and generated files unless diagnostic mode has been requested
275
282
if ( ! GenerateTemporaryTargetAssemblyDebuggingInformation )
@@ -457,6 +464,17 @@ public bool GenerateTemporaryTargetAssemblyDebuggingInformation
457
464
public string Analyzers
458
465
{ get ; set ; }
459
466
467
+ /// <summary>
468
+ /// BaseIntermediateOutputPath
469
+ ///
470
+ /// Required for Source Generator support. May be null.
471
+ ///
472
+ /// </summary>
473
+ public string BaseIntermediateOutputPath
474
+ {
475
+ get ; set ;
476
+ }
477
+
460
478
/// <summary>
461
479
/// IncludePackageReferencesDuringMarkupCompilation
462
480
///
@@ -665,7 +683,7 @@ private void AddNewProperties(XmlDocument xmlProjectDoc, List<(string PropertyNa
665
683
666
684
// Create a new PropertyGroup element
667
685
XmlNode nodeItemGroup = xmlProjectDoc . CreateElement ( "PropertyGroup" , root . NamespaceURI ) ;
668
- root . InsertAfter ( nodeItemGroup , root . FirstChild ) ;
686
+ root . PrependChild ( nodeItemGroup ) ;
669
687
670
688
// Append this new ItemGroup item into the list of children of the document root.
671
689
foreach ( var property in properties )
@@ -683,6 +701,64 @@ private void AddNewProperties(XmlDocument xmlProjectDoc, List<(string PropertyNa
683
701
}
684
702
}
685
703
704
+ //
705
+ // Replace implicit SDK imports with explicit imports
706
+ //
707
+ static private void ReplaceImplicitImports ( XmlDocument xmlProjectDoc )
708
+ {
709
+ if ( xmlProjectDoc == null )
710
+ {
711
+ // When the parameters are not valid, simply return it, instead of throwing exceptions.
712
+ return ;
713
+ }
714
+
715
+ XmlNode root = xmlProjectDoc . DocumentElement ;
716
+
717
+ for ( int i = 0 ; i < root . Attributes . Count ; i ++ )
718
+ {
719
+ XmlAttribute xmlAttribute = root . Attributes [ i ] as XmlAttribute ;
720
+
721
+ if ( xmlAttribute . Name . Equals ( "Sdk" , StringComparison . OrdinalIgnoreCase ) )
722
+ {
723
+ // <Project Sdk="Microsoft.NET.Sdk">
724
+
725
+ // Remove Sdk attribute
726
+ var sdkValue = xmlAttribute . Value ;
727
+ root . Attributes . Remove ( xmlAttribute ) ;
728
+
729
+ //
730
+ // Add explicit top import
731
+ //
732
+ // <Import Project = "Sdk.props" Sdk="Microsoft.NET.Sdk" />
733
+ //
734
+ XmlNode nodeImportProps = xmlProjectDoc . CreateElement ( "Import" , root . NamespaceURI ) ;
735
+ XmlAttribute projectAttribute = xmlProjectDoc . CreateAttribute ( "Project" , root . NamespaceURI ) ;
736
+ projectAttribute . Value = "Sdk.props" ;
737
+ nodeImportProps . Attributes . Append ( projectAttribute ) ;
738
+ nodeImportProps . Attributes . Append ( xmlAttribute ) ;
739
+
740
+ // Prepend this Import to the root of the XML document
741
+ root . PrependChild ( nodeImportProps ) ;
742
+
743
+ //
744
+ // Add explicit bottom import
745
+ //
746
+ // <Import Project = "Sdk.targets" Sdk="Microsoft.NET.Sdk"
747
+ //
748
+ XmlNode nodeImportTargets = xmlProjectDoc . CreateElement ( "Import" , root . NamespaceURI ) ;
749
+ XmlAttribute projectAttribute2 = xmlProjectDoc . CreateAttribute ( "Project" , root . NamespaceURI ) ;
750
+ projectAttribute2 . Value = "Sdk.targets" ;
751
+ XmlAttribute projectAttribute3 = xmlProjectDoc . CreateAttribute ( "Sdk" , root . NamespaceURI ) ;
752
+ projectAttribute3 . Value = sdkValue ;
753
+ nodeImportTargets . Attributes . Append ( projectAttribute2 ) ;
754
+ nodeImportTargets . Attributes . Append ( projectAttribute3 ) ;
755
+
756
+ // Append this Import to the end of the XML document
757
+ root . AppendChild ( nodeImportTargets ) ;
758
+ }
759
+ }
760
+ }
761
+
686
762
#endregion Private Methods
687
763
688
764
@@ -733,3 +809,4 @@ private void AddNewProperties(XmlDocument xmlProjectDoc, List<(string PropertyNa
733
809
734
810
#endregion GenerateProjectForLocalTypeReference Task class
735
811
}
812
+
0 commit comments