@@ -90,70 +90,28 @@ internal sealed class VirtualProjectBuildingCommand : CommandBase
9090 /// </remarks>
9191 private static readonly IEnumerable < string > s_ignorableProperties =
9292 [
93- // This is set by default by `dotnet run`, so it must be ignored otherwise the CSC optimization would not kick in by default.
93+ // These are set by default by `dotnet run`, so at least these must be ignored otherwise the CSC optimization would not kick in by default.
9494 "NuGetInteractive" ,
95+ "_BuildNonexistentProjectsByDefault" ,
96+ "RestoreUseSkipNonexistentTargets" ,
9597 ] ;
9698
9799 public static string TargetFrameworkVersion => Product . TargetFrameworkVersion ;
98100
99- internal static readonly string TargetOverrides = """
100- <!--
101- Override targets which don't work with project files that are not present on disk.
102- See https://github.com/NuGet/Home/issues/14148.
103- -->
104-
105- <Target Name="_FilterRestoreGraphProjectInputItems"
106- DependsOnTargets="_LoadRestoreGraphEntryPoints">
107- <!-- No-op, the original output is not needed by the overwritten targets. -->
108- </Target>
109-
110- <Target Name="_GetAllRestoreProjectPathItems"
111- DependsOnTargets="_FilterRestoreGraphProjectInputItems;_GenerateRestoreProjectPathWalk"
112- Returns="@(_RestoreProjectPathItems)">
113- <!-- Output from dependency _GenerateRestoreProjectPathWalk. -->
114- </Target>
115-
116- <Target Name="_GenerateRestoreGraph"
117- DependsOnTargets="_FilterRestoreGraphProjectInputItems;_GetAllRestoreProjectPathItems;_GenerateRestoreGraphProjectEntry;_GenerateProjectRestoreGraph"
118- Returns="@(_RestoreGraphEntry)">
119- <!-- Output partly from dependency _GenerateRestoreGraphProjectEntry and _GenerateProjectRestoreGraph. -->
120-
121- <ItemGroup>
122- <_GenerateRestoreGraphProjectEntryInput Include="@(_RestoreProjectPathItems)" Exclude="$(MSBuildProjectFullPath)" />
123- </ItemGroup>
124-
125- <MSBuild
126- BuildInParallel="$(RestoreBuildInParallel)"
127- Projects="@(_GenerateRestoreGraphProjectEntryInput)"
128- Targets="_GenerateRestoreGraphProjectEntry"
129- Properties="$(_GenerateRestoreGraphProjectEntryInputProperties)">
130-
131- <Output
132- TaskParameter="TargetOutputs"
133- ItemName="_RestoreGraphEntry" />
134- </MSBuild>
135-
136- <MSBuild
137- BuildInParallel="$(RestoreBuildInParallel)"
138- Projects="@(_GenerateRestoreGraphProjectEntryInput)"
139- Targets="_GenerateProjectRestoreGraph"
140- Properties="$(_GenerateRestoreGraphProjectEntryInputProperties)">
141-
142- <Output
143- TaskParameter="TargetOutputs"
144- ItemName="_RestoreGraphEntry" />
145- </MSBuild>
146- </Target>
147- """ ;
148-
149101 public VirtualProjectBuildingCommand (
150102 string entryPointFileFullPath ,
151103 MSBuildArgs msbuildArgs )
152104 {
153105 Debug . Assert ( Path . IsPathFullyQualified ( entryPointFileFullPath ) ) ;
154106
155107 EntryPointFileFullPath = entryPointFileFullPath ;
156- MSBuildArgs = msbuildArgs ;
108+ MSBuildArgs = msbuildArgs . CloneWithAdditionalProperties ( new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase )
109+ {
110+ // See https://github.com/dotnet/msbuild/blob/main/documentation/specs/build-nonexistent-projects-by-default.md.
111+ { "_BuildNonexistentProjectsByDefault" , bool . TrueString } ,
112+ { "RestoreUseSkipNonexistentTargets" , bool . FalseString } ,
113+ }
114+ . AsReadOnly ( ) ) ;
157115 }
158116
159117 public string EntryPointFileFullPath { get ; }
@@ -856,7 +814,6 @@ public static void WriteProjectFile(
856814 <Clean Include="{ EscapeValue ( artifactsPath ) } /*" />
857815 </ItemGroup>
858816
859- <!-- We need to explicitly import Sdk props/targets so we can override the targets below. -->
860817 """ ) ;
861818
862819 if ( firstSdkVersion is null )
@@ -1049,11 +1006,7 @@ public static void WriteProjectFile(
10491006 """ ) ;
10501007 }
10511008
1052- writer . WriteLine ( $ """
1053-
1054- { TargetOverrides }
1055-
1056- """ ) ;
1009+ writer . WriteLine ( ) ;
10571010 }
10581011
10591012 writer . WriteLine ( """
0 commit comments