Skip to content
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

[release/9.0.2xx] Allow ProjectReferences to not have the _GetRequiredWorkloads Target #44701

Merged
merged 3 commits into from
Nov 7, 2024
Merged
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
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();
}
}
Loading