Skip to content

Remove MSBuild hacks for virtual project building #49745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<add key="richnav" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-buildservices/nuget/v3/index.json" />
<!-- mstest dependencies -->
<add key="test-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json" />
<add key="temporary" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/general-testing/nuget/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@
At usage sites, either we use MicrosoftBuildMinimumVersion, or MicrosoftBuildVersion in source-only modes.

Additionally, set the MinimumVSVersion for the installer UI that's required for targeting NetCurrent -->
<MicrosoftBuildVersion>17.15.0-preview-25359-101</MicrosoftBuildVersion>
<MicrosoftBuildLocalizationVersion>17.15.0-preview-25359-101</MicrosoftBuildLocalizationVersion>
<MicrosoftBuildVersion>17.15.0-preview-25361-09</MicrosoftBuildVersion>
<MicrosoftBuildLocalizationVersion>17.15.0-preview-25361-09</MicrosoftBuildLocalizationVersion>
<MicrosoftBuildMinimumVersion Condition="'$(DotNetBuildSourceOnly)' != 'true'">17.11.4</MicrosoftBuildMinimumVersion>
<MinimumVSVersion>17.13</MinimumVSVersion>
</PropertyGroup>
Expand Down
60 changes: 6 additions & 54 deletions src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,64 +61,19 @@ internal sealed class VirtualProjectBuildingCommand : CommandBase
"MSBuild.rsp",
];

internal static readonly string TargetOverrides = """
<!--
Override targets which don't work with project files that are not present on disk.
See https://github.com/NuGet/Home/issues/14148.
-->

<Target Name="_FilterRestoreGraphProjectInputItems"
DependsOnTargets="_LoadRestoreGraphEntryPoints">
<!-- No-op, the original output is not needed by the overwritten targets. -->
</Target>

<Target Name="_GetAllRestoreProjectPathItems"
DependsOnTargets="_FilterRestoreGraphProjectInputItems;_GenerateRestoreProjectPathWalk"
Returns="@(_RestoreProjectPathItems)">
<!-- Output from dependency _GenerateRestoreProjectPathWalk. -->
</Target>

<Target Name="_GenerateRestoreGraph"
DependsOnTargets="_FilterRestoreGraphProjectInputItems;_GetAllRestoreProjectPathItems;_GenerateRestoreGraphProjectEntry;_GenerateProjectRestoreGraph"
Returns="@(_RestoreGraphEntry)">
<!-- Output partly from dependency _GenerateRestoreGraphProjectEntry and _GenerateProjectRestoreGraph. -->

<ItemGroup>
<_GenerateRestoreGraphProjectEntryInput Include="@(_RestoreProjectPathItems)" Exclude="$(MSBuildProjectFullPath)" />
</ItemGroup>

<MSBuild
BuildInParallel="$(RestoreBuildInParallel)"
Projects="@(_GenerateRestoreGraphProjectEntryInput)"
Targets="_GenerateRestoreGraphProjectEntry"
Properties="$(_GenerateRestoreGraphProjectEntryInputProperties)">

<Output
TaskParameter="TargetOutputs"
ItemName="_RestoreGraphEntry" />
</MSBuild>

<MSBuild
BuildInParallel="$(RestoreBuildInParallel)"
Projects="@(_GenerateRestoreGraphProjectEntryInput)"
Targets="_GenerateProjectRestoreGraph"
Properties="$(_GenerateRestoreGraphProjectEntryInputProperties)">

<Output
TaskParameter="TargetOutputs"
ItemName="_RestoreGraphEntry" />
</MSBuild>
</Target>
""";

public VirtualProjectBuildingCommand(
string entryPointFileFullPath,
MSBuildArgs msbuildArgs)
{
Debug.Assert(Path.IsPathFullyQualified(entryPointFileFullPath));

EntryPointFileFullPath = entryPointFileFullPath;
MSBuildArgs = msbuildArgs;
MSBuildArgs = msbuildArgs.CloneWithAdditionalProperties(new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "BuildNonexistentProjectsByDefault", bool.TrueString },
{ "RestoreUseSkipNonexistentTargets", bool.FalseString },
}
.AsReadOnly());
}

public string EntryPointFileFullPath { get; }
Expand Down Expand Up @@ -780,9 +735,6 @@ public static void WriteProjectFile(
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
""");
}

writer.WriteLine();
writer.WriteLine(TargetOverrides);
}

writer.WriteLine("""
Expand Down
6 changes: 0 additions & 6 deletions test/dotnet.Tests/CommandTests/Run/RunFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1893,8 +1893,6 @@ public void Api()
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
<Import Project="Sdk.targets" Sdk="Aspire.Hosting.Sdk" Version="9.1.0" />

{VirtualProjectBuildingCommand.TargetOverrides}

</Project>

""")}},"Diagnostics":[]}
Expand Down Expand Up @@ -1961,8 +1959,6 @@ public void Api_Diagnostic_01()

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

{VirtualProjectBuildingCommand.TargetOverrides}

</Project>

""")}},"Diagnostics":
Expand Down Expand Up @@ -2033,8 +2029,6 @@ public void Api_Diagnostic_02()

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

{VirtualProjectBuildingCommand.TargetOverrides}

</Project>

""")}},"Diagnostics":
Expand Down
Loading