Skip to content

Commit c30cb15

Browse files
committed
Add a test to confirm that we can workload restore solutions with projects that do not support workloads.
1 parent d6cfec6 commit c30cb15

File tree

7 files changed

+103
-2
lines changed

7 files changed

+103
-2
lines changed

src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommand.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.CommandLine;
55
using Microsoft.Build.Construction;
66
using Microsoft.Build.Execution;
7-
using Microsoft.Build.Framework;
87
using Microsoft.Build.Logging;
98
using Microsoft.DotNet.Cli;
109
using Microsoft.DotNet.Cli.Utils;
@@ -53,7 +52,6 @@ private List<WorkloadId> RunTargetToGetWorkloadIds(IEnumerable<string> allProjec
5352
{"SkipResolvePackageAssets", "true"}
5453
};
5554

56-
5755
var allWorkloadId = new List<WorkloadId>();
5856
foreach (string projectFile in allProjects)
5957
{
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.NET.TestFramework.Commands;
5+
6+
public class DotnetWorkloadCommand : DotnetCommand
7+
{
8+
public DotnetWorkloadCommand(ITestOutputHelper log, params string[] args) : base(log)
9+
{
10+
Arguments.Add("workload");
11+
Arguments.AddRange(args);
12+
}
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.Docker.Sdk">
2+
<PropertyGroup Label="Globals">
3+
<ProjectVersion>2.1</ProjectVersion>
4+
<DockerTargetOS>Windows</DockerTargetOS>
5+
<ProjectGuid>154022c1-8014-4e9d-bd78-6ff46670ffa4</ProjectGuid>
6+
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
7+
<DockerServiceUrl>{Scheme}://{ServiceIPAddress}{ServicePort}</DockerServiceUrl>
8+
<DockerServiceName>webapplication1</DockerServiceName>
9+
<DockerComposeBaseFilePath>DockerComposeFiles\mydockercompose</DockerComposeBaseFilePath>
10+
<AdditionalComposeFilePaths>AdditionalComposeFiles\myadditionalcompose.yml</AdditionalComposeFilePaths>
11+
<ProjectTypeGuids>E53339B2-1760-4266-BCC7-CA923CBCF16C</ProjectTypeGuids>
12+
</PropertyGroup>
13+
<ItemGroup>
14+
<None Include="DockerComposeFiles\mydockercompose.override.yml">
15+
<DependentUpon>DockerComposeFiles\mydockercompose.yml</DependentUpon>
16+
</None>
17+
<None Include="DockerComposeFiles\mydockercompose.yml" />
18+
<None Include=".dockerignore" />
19+
</ItemGroup>
20+
</Project>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// See https://aka.ms/new-console-template for more information
2+
Console.WriteLine("Hello, World!");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleApp", "SampleApp\SampleApp.csproj", "{99463187-C4F6-4A68-82AD-2BBB08DBF872}"
7+
EndProject
8+
Project("E53339B2-1760-4266-BCC7-CA923CBCF16C") = "SampleApp.Docker", "SampleApp.Docker\SampleApp.Docker.dcproj", "{154022C1-8014-4E9D-BD78-6FF46670FFA4}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(SolutionProperties) = preSolution
16+
HideSolutionNode = FALSE
17+
EndGlobalSection
18+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19+
{99463187-C4F6-4A68-82AD-2BBB08DBF872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{99463187-C4F6-4A68-82AD-2BBB08DBF872}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{99463187-C4F6-4A68-82AD-2BBB08DBF872}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{99463187-C4F6-4A68-82AD-2BBB08DBF872}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{154022C1-8014-4E9D-BD78-6FF46670FFA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{154022C1-8014-4E9D-BD78-6FF46670FFA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{154022C1-8014-4E9D-BD78-6FF46670FFA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{154022C1-8014-4E9D-BD78-6FF46670FFA4}.Release|Any CPU.Build.0 = Release|Any CPU
27+
EndGlobalSection
28+
EndGlobal
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.DotNet.Cli.Workload.Restore.Tests;
5+
6+
public class GivenDotnetWorkloadRestore : SdkTest
7+
{
8+
public GivenDotnetWorkloadRestore(ITestOutputHelper log) : base(log)
9+
{
10+
}
11+
12+
public static string DcProjAssetName = "SolutionWithAppAndDcProj";
13+
14+
[Fact]
15+
public void ProjectsThatDoNotSupportWorkloadsAreNotInspected()
16+
{
17+
var projectPath =
18+
_testAssetsManager
19+
.CopyTestAsset(DcProjAssetName)
20+
.WithSource()
21+
.Path;
22+
23+
new DotnetWorkloadCommand(Log, "restore")
24+
.WithWorkingDirectory(projectPath)
25+
.Execute()
26+
.Should()
27+
// if we did try to restore the dcproj in this TestAsset we would fail, so passing means we didn't!
28+
.Pass();
29+
}
30+
}

0 commit comments

Comments
 (0)