Skip to content
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 @@ -38,13 +38,30 @@
</PropertyGroup>

<!--
MTP scenario (EnableMSTestRunner): the UI language is chosen at runtime (for example via
TESTINGPLATFORM_UI_LANGUAGE / DOTNET_CLI_UI_LANGUAGE), so the build-machine culture is irrelevant.
Every requested localized satellite must be copied to the output directory so any selected culture can be resolved at run time.
-->
<ItemGroup Condition=" '$(EnableMSTestRunner)' == 'true' ">
<_MSTestV2Files Include="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\_localization'))\**\*.dll" />
<!-- Set UICulture from the satellite's culture folder. This is done via Update (not inline on Include) because
the well-known %(RecursiveDir) metadata is only available on items after they have been created. -->
<_MSTestV2Files Update="@(_MSTestV2Files)">
<UICulture>%(RecursiveDir)</UICulture>
<Culture>$([System.String]::Copy('%(RecursiveDir)').TrimEnd('\').TrimEnd('/').ToLowerInvariant())</Culture>
</_MSTestV2Files>
</ItemGroup>

<!--
VSTest scenario: the UI language is fixed to the build-machine culture, so only that culture's hierarchy
is copied to keep the output directory slim.
Only traversing 5 levels in the culture hierarchy. This is the maximum length for all cultures and should be sufficient
to get to a culture name that maps to a resource folder we package.
The root culture name for all cultures is invariant whose name is '' (empty) and the parent for invariant culture is
invariant itself. (https://msdn.microsoft.com/library/system.globalization.cultureinfo.parent.aspx)
So the below code should not break build in any case.
-->
<ItemGroup>
<ItemGroup Condition=" '$(EnableMSTestRunner)' != 'true' ">
<CurrentUICultureHierarchy Include="$([System.Globalization.CultureInfo]::CurrentUICulture.Name)" />
<CurrentUICultureHierarchy Include="$([System.Globalization.CultureInfo]::CurrentUICulture.Parent.Name)" Condition=" '$([System.Globalization.CultureInfo]::CurrentUICulture.Parent.Name)' != '' "/>
<CurrentUICultureHierarchy Include="$([System.Globalization.CultureInfo]::CurrentUICulture.Parent.Parent.Name)" Condition=" '$([System.Globalization.CultureInfo]::CurrentUICulture.Parent.Parent.Name)' != '' "/>
Expand All @@ -57,11 +74,14 @@
This is populated here (rather than inside CopyMSTestV2Resources) so the item group is available when the
Inputs/Outputs of CopyMSTestV2Resources are evaluated for incremental build.
-->
<ItemGroup>
<ItemGroup Condition=" '$(EnableMSTestRunner)' != 'true' ">
<_MSTestV2Files Include="$(MSBuildThisFileDirectory)..\_localization\%(CurrentUICultureHierarchy.Identity)\*.dll">
<UICulture>%(CurrentUICultureHierarchy.Identity)</UICulture>
<Culture>$([System.String]::Copy('%(CurrentUICultureHierarchy.Identity)').ToLowerInvariant())</Culture>
</_MSTestV2Files>
</ItemGroup>

<ItemGroup>
<MSTestV2Files Include="@(_MSTestV2Files)"
Condition=" '$(SatelliteResourceLanguages)' == '' OR $([System.String]::Copy('$(_MSTestSatelliteResourceLanguagesWithDelimiters)').Contains(';%(_MSTestV2Files.Culture);')) " />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,47 @@ public async Task SatelliteResourceLanguages_FiltersClassicUwpAdapterResources(s
result.AssertOutputContains($"SatelliteCultures=[{expectedCultures}]");
}

[TestMethod]
[OSCondition(OperatingSystems.Windows, IgnoreMessage = "Classic UWP package assets are produced only on Windows.")]
public async Task SatelliteResourceLanguages_FiltersClassicUwpMtpAdapterResources()
{
const string Source = """
#file ClassicUwpMtpSatelliteResources.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$TargetFramework$</TargetFramework>
<EnableMSTestRunner>true</EnableMSTestRunner>
<SatelliteResourceLanguages>fr;ja</SatelliteResourceLanguages>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="$MSTestVersion$" GeneratePathProperty="true" ExcludeAssets="all" />
</ItemGroup>

<Import Project="$(PkgMSTest_TestAdapter)\buildTransitive\uap10.0\MSTest.TestAdapter.targets"
Condition=" '$(PkgMSTest_TestAdapter)' != '' " />

<Target Name="PrintSatelliteCultures" DependsOnTargets="GetMSTestV2CultureHierarchy">
<Message Text="SatelliteCultures=[@(MSTestV2Files->'%(Culture)')]" Importance="High" />
</Target>
</Project>
""";

using TestAsset testAsset = await TestAsset.GenerateAssetAsync(
$"{AssetName}ClassicUwpMtpSatellites",
Source
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)
.PatchCodeWithReplace("$TargetFramework$", TargetFrameworks.NetCurrent));

DotnetMuxerResult result = await DotnetCli.RunAsync(
$"msbuild {testAsset.TargetAssetPath} -restore -t:PrintSatelliteCultures",
environmentVariables: new() { ["DOTNET_CLI_UI_LANGUAGE"] = "de" },
cancellationToken: TestContext.CancellationToken);

result.AssertExitCodeIs(0);
result.AssertOutputContains("SatelliteCultures=[fr;fr;ja;ja]");
}

[TestMethod]
[DynamicData(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration), typeof(AcceptanceTestBase<NopAssetFixture>))]
public async Task RunTests_With_CentralPackageManagement_Standalone(string multiTfm, BuildConfiguration buildConfiguration)
Expand Down
Loading