Skip to content

Commit

Permalink
[release/9.0.2xx] Allow ProjectReferences to not have the _GetRequire…
Browse files Browse the repository at this point in the history
…dWorkloads Target (#44701)

Co-authored-by: Chet Husk <chusk3@gmail.com>
Co-authored-by: Chet Husk <baronfel@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 7, 2024
1 parent c5a3964 commit 9406078
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ Copyright (c) .NET Foundation. All rights reserved.
</Target>

<!-- This target is not part of the build. Only used by dotnet workload restore command. Global property "SkipResolvePackageAssets"
need to be set to "true" to avoid requiring restore (which would likely fail if the required workloads aren't already installed).-->
need to be set to "true" to avoid requiring restore (which would likely fail if the required workloads aren't already installed).
In addition, since this is a target that is called on potentially-unsupported project types like esproj, we need to not fail
if the Target is missing. -->
<Target Name="_GetRequiredWorkloads" DependsOnTargets="GetSuggestedWorkloads;PrepareProjectReferences" Returns="@(_ResolvedSuggestedWorkload)">
<MSBuild
Projects="@(_MSBuildProjectReferenceExistent)"
Targets="_GetRequiredWorkloads"
BuildInParallel="$(BuildInParallel)"
Condition="'%(_MSBuildProjectReferenceExistent.BuildReference)' == 'true' and '@(_MSBuildProjectReferenceExistent)' != ''"
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)$(_GlobalPropertiesToRemoveFromProjectReferences);TargetFramework;TargetFrameworks">
RemoveProperties="%(_MSBuildProjectReferenceExistent.GlobalPropertiesToRemove)$(_GlobalPropertiesToRemoveFromProjectReferences);TargetFramework;TargetFrameworks"
SkipNonexistentTargets="true" >
<Output TaskParameter="TargetOutputs" ItemName="SuggestedWorkloadFromReference"/>
</MSBuild>

Expand Down
10 changes: 10 additions & 0 deletions test/TestAssets/TestProjects/ProjectWithEsProjReference/App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="./Lib.esproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Project Sdk="Microsoft.VisualStudio.JavaScript.SDK/1.0.1948920" />

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "lib",
"version": "1.0.0",
"description": "A test project to verify .NET SDK compatibility for workload restore and non-Managed projects",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT"
}
18 changes: 18 additions & 0 deletions test/dotnet-workload-restore.Tests/GivenDotnetWorkloadRestore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public GivenDotnetWorkloadRestore(ITestOutputHelper log) : base(log)
}

public static string DcProjAssetName = "SolutionWithAppAndDcProj";
public static string TransitiveReferenceNoWorkloadsAssetName = "ProjectWithEsProjReference";

[Fact]
public void ProjectsThatDoNotSupportWorkloadsAreNotInspected()
Expand All @@ -27,4 +28,21 @@ public void ProjectsThatDoNotSupportWorkloadsAreNotInspected()
// if we did try to restore the dcproj in this TestAsset we would fail, so passing means we didn't!
.Pass();
}

[Fact]
public void ProjectsThatDoNotSupportWorkloadsAndAreTransitivelyReferencedDoNotBreakTheBuild()
{
var projectPath =
_testAssetsManager
.CopyTestAsset(TransitiveReferenceNoWorkloadsAssetName)
.WithSource()
.Path;

new DotnetWorkloadCommand(Log, "restore")
.WithWorkingDirectory(projectPath)
.Execute()
.Should()
// if we did try to restore the esproj in this TestAsset we would fail, so passing means we didn't!
.Pass();
}
}

0 comments on commit 9406078

Please sign in to comment.