Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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 @@ -72,6 +72,10 @@ Copyright (c) .NET Foundation. All rights reserved.
<UserProfileRuntimeStorePath Condition="'$(UserProfileRuntimeStorePath)' == ''">$(_DefaultUserProfileRuntimeStorePath)</UserProfileRuntimeStorePath>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0'))">
<PredefinedCulturesOnly Condition="'$(InvariantGlobalization)' == 'true' And '$(PredefinedCulturesOnly)' == ''">true</PredefinedCulturesOnly>
</PropertyGroup>

<!-- Opt into .NET Core resource-serialization strategy by default when targeting frameworks
that support it by default.
-->
Expand Down Expand Up @@ -394,6 +398,11 @@ Copyright (c) .NET Foundation. All rights reserved.
Value="$(InvariantGlobalization)"
Trim="true" />

<RuntimeHostConfigurationOption Include="System.Globalization.PredefinedCulturesOnly"
Condition="'$(PredefinedCulturesOnly)' != ''"
Value="$(PredefinedCulturesOnly)"
Trim="true" />

<RuntimeHostConfigurationOption Include="System.Net.Http.EnableActivityPropagation"
Condition="'$(HttpActivityPropagationSupport)' != ''"
Value="$(HttpActivityPropagationSupport)"
Expand Down Expand Up @@ -961,7 +970,7 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->

<UsingTask TaskName="CheckForUnsupportedWinMDReferences" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
<UsingTask TaskName="CheckForUnsupportedWinMDReferences" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />

<Target Name="_BlockWinMDsOnUnsupportedTFMs"
AfterTargets="PreBuildEvent"
Expand All @@ -972,7 +981,7 @@ Copyright (c) .NET Foundation. All rights reserved.
TargetFrameworkMoniker="$(TargetFrameworkMoniker)"
ReferencePaths="@(ReferencePath)"
/>

<NETSdkError Condition="'$(OutputType)' == 'winmdobj'"
ResourceName="WinMDObjNotSupportedOnTargetFramework"
FormatArguments="$(TargetFrameworkMoniker)" />
Expand Down Expand Up @@ -1052,7 +1061,7 @@ Copyright (c) .NET Foundation. All rights reserved.
IsExecutable="$(_IsExecutable)"
ReferencedProjects="@(_MSBuildProjectReferenceExistent)"
/>

</Target>

<!--
Expand Down Expand Up @@ -1105,7 +1114,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup Condition=" '$(ImportWindowsDesktopTargets)' == 'true'">
<AfterMicrosoftNETSdkTargets>$(AfterMicrosoftNETSdkTargets);$(MSBuildThisFileDirectory)../../Microsoft.NET.Sdk.WindowsDesktop/targets/Microsoft.NET.Sdk.WindowsDesktop.targets</AfterMicrosoftNETSdkTargets>
</PropertyGroup>

<!-- Note: Once WindowsDesktop is a workload this will be moved to WorkloadManifest.targets -->
<ItemGroup Condition="'$(MicrosoftNETWindowsWorkloadInstalled)' == 'true' and
'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ internal static List<string> GetValuesFromTestLibrary(
ITestOutputHelper log,
TestAssetsManager testAssetsManager,
string itemTypeOrPropertyName,
Action<GetValuesCommand> setup = null,
Action<GetValuesCommand> setup = null,
string[] msbuildArgs = null,
GetValuesCommand.ValueType valueType = GetValuesCommand.ValueType.Item,
[CallerMemberName] string callingMethod = "",
GetValuesCommand.ValueType valueType = GetValuesCommand.ValueType.Item,
[CallerMemberName] string callingMethod = "",
Action<XDocument> projectChanges = null,
string identifier = null)
{
Expand Down Expand Up @@ -316,14 +316,14 @@ public void It_implicitly_defines_compilation_constants_for_the_configuration(st
[InlineData("netstandard1.6", new[] { "NETSTANDARD", "NETSTANDARD1_6", "NETSTANDARD1_0_OR_GREATER", "NETSTANDARD1_1_OR_GREATER", "NETSTANDARD1_2_OR_GREATER",
"NETSTANDARD1_3_OR_GREATER", "NETSTANDARD1_4_OR_GREATER", "NETSTANDARD1_5_OR_GREATER", "NETSTANDARD1_6_OR_GREATER" })]
[InlineData("net45", new[] { "NETFRAMEWORK", "NET45", "NET20_OR_GREATER", "NET30_OR_GREATER", "NET35_OR_GREATER", "NET40_OR_GREATER", "NET45_OR_GREATER" })]
[InlineData("net461", new[] { "NETFRAMEWORK", "NET461", "NET20_OR_GREATER", "NET30_OR_GREATER", "NET35_OR_GREATER", "NET40_OR_GREATER", "NET45_OR_GREATER",
[InlineData("net461", new[] { "NETFRAMEWORK", "NET461", "NET20_OR_GREATER", "NET30_OR_GREATER", "NET35_OR_GREATER", "NET40_OR_GREATER", "NET45_OR_GREATER",
"NET451_OR_GREATER", "NET452_OR_GREATER", "NET46_OR_GREATER", "NET461_OR_GREATER" })]
[InlineData("net48", new[] { "NETFRAMEWORK", "NET48", "NET20_OR_GREATER", "NET30_OR_GREATER", "NET35_OR_GREATER", "NET40_OR_GREATER", "NET45_OR_GREATER",
[InlineData("net48", new[] { "NETFRAMEWORK", "NET48", "NET20_OR_GREATER", "NET30_OR_GREATER", "NET35_OR_GREATER", "NET40_OR_GREATER", "NET45_OR_GREATER",
"NET451_OR_GREATER", "NET452_OR_GREATER", "NET46_OR_GREATER", "NET461_OR_GREATER", "NET462_OR_GREATER", "NET47_OR_GREATER", "NET471_OR_GREATER", "NET472_OR_GREATER", "NET48_OR_GREATER" })]
[InlineData("netcoreapp1.0", new[] { "NETCOREAPP", "NETCOREAPP1_0", "NETCOREAPP1_0_OR_GREATER" })]
[InlineData("netcoreapp3.0", new[] { "NETCOREAPP", "NETCOREAPP3_0", "NETCOREAPP1_0_OR_GREATER", "NETCOREAPP1_1_OR_GREATER", "NETCOREAPP2_0_OR_GREATER",
[InlineData("netcoreapp3.0", new[] { "NETCOREAPP", "NETCOREAPP3_0", "NETCOREAPP1_0_OR_GREATER", "NETCOREAPP1_1_OR_GREATER", "NETCOREAPP2_0_OR_GREATER",
"NETCOREAPP2_1_OR_GREATER", "NETCOREAPP2_2_OR_GREATER", "NETCOREAPP3_0_OR_GREATER" })]
[InlineData("net5.0", new[] { "NETCOREAPP", "NETCOREAPP1_0_OR_GREATER", "NETCOREAPP1_1_OR_GREATER", "NETCOREAPP2_0_OR_GREATER", "NETCOREAPP2_1_OR_GREATER",
[InlineData("net5.0", new[] { "NETCOREAPP", "NETCOREAPP1_0_OR_GREATER", "NETCOREAPP1_1_OR_GREATER", "NETCOREAPP2_0_OR_GREATER", "NETCOREAPP2_1_OR_GREATER",
"NETCOREAPP2_2_OR_GREATER", "NETCOREAPP3_0_OR_GREATER", "NETCOREAPP3_1_OR_GREATER", "NET", "NET5_0", "NET5_0_OR_GREATER" })]
[InlineData(".NETPortable,Version=v4.5,Profile=Profile78", new string[] { })]
[InlineData(".NETFramework,Version=v4.0,Profile=Client", new string[] { "NETFRAMEWORK", "NET40", "NET20_OR_GREATER", "NET30_OR_GREATER", "NET35_OR_GREATER", "NET40_OR_GREATER" })]
Expand Down Expand Up @@ -366,7 +366,7 @@ public void It_implicitly_defines_compilation_constants_for_the_target_framework
targetFrameworkProperties.Single().SetValue(targetFramework);
}
});

var libraryProjectDirectory = Path.Combine(testAsset.TestRoot, "TestLibrary");

var getValuesCommand = new GetValuesCommand(Log, libraryProjectDirectory,
Expand Down Expand Up @@ -423,7 +423,7 @@ public void It_implicitly_defines_compilation_constants_for_the_target_platform(
}
});

AssertDefinedConstantsOutput(testAsset, targetFramework,
AssertDefinedConstantsOutput(testAsset, targetFramework,
new[] { "NETCOREAPP", "NETCOREAPP1_0_OR_GREATER", "NETCOREAPP1_1_OR_GREATER", "NETCOREAPP2_0_OR_GREATER", "NETCOREAPP2_1_OR_GREATER", "NETCOREAPP2_2_OR_GREATER", "NETCOREAPP3_0_OR_GREATER", "NETCOREAPP3_1_OR_GREATER", "NET", "NET5_0", "NET5_0_OR_GREATER" }
.Concat(expectedDefines).ToArray());
}
Expand Down Expand Up @@ -841,6 +841,62 @@ public void It_marks_package_references_as_externally_resolved(bool? markAsExter
}
}

[Theory]
[InlineData("net5.0", false, false, false, "False,False")] // Pre .NET 6.0 predefinedCulturesOnly always false (no exist)
[InlineData("net5.0", true, false, false, "True,False")] // Pre .NET 6.0 predefinedCulturesOnly always false (no exist)
[InlineData("net5.0", false, true, true, "False,False")] // Pre .NET 6.0 predefinedCulturesOnly always false (no exist)
[InlineData("net5.0", true, true, true, "True,False")] // Pre .NET 6.0 predefinedCulturesOnly always false (no exist)
[InlineData("net6.0", false, false, false, "False,False")] // predefinedCulturesOnly default value is false when Invariant is false or not defined
[InlineData("net6.0", false, false, true, "False,False")] // predefinedCulturesOnly explicitly defined as false.
[InlineData("net6.0", false, true, true, "False,True")] // predefinedCulturesOnly explicitly defined as true.
[InlineData("net6.0", true, false, false, "True,True")] // predefinedCulturesOnly default value is true when Invariant is true
[InlineData("net6.0", true, false, true, "True,False")] // predefinedCulturesOnly explicitly defined as false.
[InlineData("net6.0", true, true, true, "True,True")] // predefinedCulturesOnly explicitly defined as true.
public void It_can_implicitly_define_predefined_Cultures_only(string targetFramework, bool invariantValue, bool predefinedCulturesOnlyValue, bool definePredefinedCulturesOnly, string expectedPredefinedCulturesOnlyValue)
{
var testProj = new TestProject()
{
Name = "CheckPredefineCulturesOnly",
TargetFrameworks = targetFramework,
IsExe = true,
};

testProj.AdditionalProperties["InvariantGlobalization"] = invariantValue ? "true" : "false";

if (definePredefinedCulturesOnly)
{
testProj.AdditionalProperties["PredefinedCulturesOnly"] = predefinedCulturesOnlyValue ? "true" : "false";
}

var testAsset = _testAssetsManager.CreateTestProject(testProj, identifier: $"{targetFramework}{invariantValue}{predefinedCulturesOnlyValue}{definePredefinedCulturesOnly}");
File.WriteAllText(Path.Combine(testAsset.Path, testProj.Name, $"{testProj.Name}.cs"), @"
using System;
using System.Reflection;
class Program
{
static void Main(string[] args)
{
bool invariant = false;
bool predefinedCulturesOnly = false;
try { invariant = (bool) typeof(object).Assembly.GetType(""System.Globalization.GlobalizationMode"").GetProperty(""Invariant"", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); } catch {}
try { predefinedCulturesOnly = (bool) typeof(object).Assembly.GetType(""System.Globalization.GlobalizationMode"").GetProperty(""PredefinedCulturesOnly"", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); } catch {}

Console.WriteLine($""{invariant},{predefinedCulturesOnly}"");
}
}
");

var buildCommand = new BuildCommand(testAsset);
buildCommand
.Execute()
.Should()
.Pass();

var runCommand = new RunExeCommand(Log, Path.Combine(buildCommand.GetOutputDirectory(targetFramework).FullName, $"{testProj.Name}.exe"));
var stdOut = runCommand.Execute().StdOut.Split(Environment.NewLine.ToCharArray()).Where(line => !string.IsNullOrWhiteSpace(line));
stdOut.Should().BeEquivalentTo(expectedPredefinedCulturesOnlyValue);
}

[Theory]
[InlineData("netcoreapp2.2", null, false, null, false)]
[InlineData("netcoreapp3.0", null, true, null, true)]
Expand Down