@@ -90,70 +90,28 @@ internal sealed class VirtualProjectBuildingCommand : CommandBase
90
90
/// </remarks>
91
91
private static readonly IEnumerable < string > s_ignorableProperties =
92
92
[
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.
94
94
"NuGetInteractive" ,
95
+ "_BuildNonexistentProjectsByDefault" ,
96
+ "RestoreUseSkipNonexistentTargets" ,
95
97
] ;
96
98
97
99
public static string TargetFrameworkVersion => Product . TargetFrameworkVersion ;
98
100
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
-
149
101
public VirtualProjectBuildingCommand (
150
102
string entryPointFileFullPath ,
151
103
MSBuildArgs msbuildArgs )
152
104
{
153
105
Debug . Assert ( Path . IsPathFullyQualified ( entryPointFileFullPath ) ) ;
154
106
155
107
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 ( ) ) ;
157
115
}
158
116
159
117
public string EntryPointFileFullPath { get ; }
@@ -856,7 +814,6 @@ public static void WriteProjectFile(
856
814
<Clean Include="{ EscapeValue ( artifactsPath ) } /*" />
857
815
</ItemGroup>
858
816
859
- <!-- We need to explicitly import Sdk props/targets so we can override the targets below. -->
860
817
""" ) ;
861
818
862
819
if ( firstSdkVersion is null )
@@ -1049,11 +1006,7 @@ public static void WriteProjectFile(
1049
1006
""" ) ;
1050
1007
}
1051
1008
1052
- writer . WriteLine ( $ """
1053
-
1054
- { TargetOverrides }
1055
-
1056
- """ ) ;
1009
+ writer . WriteLine ( ) ;
1057
1010
}
1058
1011
1059
1012
writer . WriteLine ( """
0 commit comments