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

use different values for $(TargetPlatformVersion) for TFM and dependency discovery #11718

Merged
merged 1 commit into from
Mar 3, 2025
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 @@ -479,6 +479,51 @@ await TestDiscoverAsync(
);
}

[Fact]
public async Task DependenciesCanBeDiscoveredWithWindowsSpecificTfm()
{
await TestDiscoverAsync(
packages:
[
MockNuGetPackage.CreateSimplePackage("Some.Dependency", "1.2.3", "netstandard2.0"),
],
startingDirectory: "src",
projectPath: "src/library.csproj",
files:
[
("src/library.csproj", """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0-windows</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Some.Dependency" Version="1.2.3" />
</ItemGroup>
</Project>
""")
],
expectedProjects:
[
new()
{
FilePath = "library.csproj",
Dependencies =
[
new("Some.Dependency", "1.2.3", DependencyType.PackageReference, TargetFrameworks: ["net9.0-windows"], IsDirect: true),
],
ImportedFiles = [],
Properties =
[
new("TargetFramework", "net9.0-windows", "src/library.csproj"),
],
TargetFrameworks = ["net9.0-windows"],
ReferencedProjectPaths = [],
AdditionalFiles = [],
},
]
);
}

private static async Task TestDiscoverAsync(string startingDirectory, string projectPath, TestFile[] files, ImmutableArray<ExpectedSdkProjectDiscoveryResult> expectedProjects, MockNuGetPackage[]? packages = null)
{
using var testDirectory = await TemporaryDirectory.CreateWithContentsAsync(files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,18 @@ public static IEnumerable<object[]> GetTargetFrameworkValuesFromProjectData()
new[] { "net8.0-windows7.0" }
];

yield return
[
"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0-windows</TargetFramework>
</PropertyGroup>
</Project>
""",
new[] { "net9.0-windows" }
];

// legacy projects
yield return
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<Project>
<!-- The following properties enable target framework and dependency discovery when OS-specific workloads are required -->
<PropertyGroup>
<!--

$(TargetPlatformVersion) should default to '0.0' as per https://github.com/dotnet/sdk/blob/v9.0.100/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.TargetFrameworkInference.targets#L69

HOWEVER, this will need to be set differently (e.g., '1.0') to do dependency discovery

-->
<_DefaultTargetPlatformVersion Condition="'$(_DefaultTargetPlatformVersion)' == ''">0.0</_DefaultTargetPlatformVersion>
<DesignTimeBuild>true</DesignTimeBuild>
<EnableWindowsTargeting Condition="$(TargetFramework.Contains('-windows'))">true</EnableWindowsTargeting>
<TargetPlatformVersion Condition="$(TargetPlatformVersion) == '' AND $(TargetFramework.Contains('-'))">1.0</TargetPlatformVersion>
<TargetPlatformVersion Condition="$(TargetPlatformVersion) == '' AND $(TargetFramework.Contains('-'))">$(_DefaultTargetPlatformVersion)</TargetPlatformVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<Project>
<PropertyGroup>
<!-- Dependency discovery requires a non-zero value for $(TargetPlatformVersion) -->
<_DefaultTargetPlatformVersion>1.0</_DefaultTargetPlatformVersion>
</PropertyGroup>

<Import Project="DependencyDiscovery.props" />

<Target Name="_DiscoverDependencies" DependsOnTargets="ResolveAssemblyReferences;GenerateBuildDependencyFile;ResolvePackageAssets">
Expand Down
Loading