Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 additions & 2 deletions src/Assets/TestProjects/KitchenSink/TestApp/TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be setting the <PredefinedCulturesOnly> property in the top PropertyGroup of this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsplaisted I have returned back the changes in GivenThatWeWantToPublishAProjectWithAllFeatures.cs and TestApp as @eerhardt suggested to keep it to test the behavior when enabling the property in down-level version even if it will not have any runtime effect.

<None Include="NoneCopyOutputAlways.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand All @@ -74,7 +74,7 @@
<ProjectReference Include="../TestLibrary/TestLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<!--
<!--
The TestLibrary has a hard dependency on Newtonsoft.Json.
The TestApp has a PrivateAssets=All dependency on Microsoft.Extensions.DependencyModel.
Microsoft.Extensions.DependencyModel depends on Newtonsoft.Json.
Expand Down
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, targetFramework);
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(Log, Path.Combine(testAsset.Path, testProj.Name));
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void It_publishes_the_project_correctly(string targetFramework, string []
}
}");
baselineConfigJsonObject["runtimeOptions"]["tfm"] = targetFramework;
baselineConfigJsonObject["runtimeOptions"]["framework"]["version"] =
baselineConfigJsonObject["runtimeOptions"]["framework"]["version"] =
targetFramework == "netcoreapp1.0" ? "1.0.5" : "1.1.2";

runtimeConfigJsonObject
Expand Down Expand Up @@ -146,7 +146,7 @@ public void It_does_not_build_when_nobuild_is_set(string targetFramework, string
{
File.GetLastWriteTimeUtc(file)
.Should().Be(
modificationTime,
modificationTime,
because: $"Publish with NoBuild=true should not overwrite {file}");
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ private static void VerifyDependency(
library.RuntimeAssemblyGroups[0].Runtime.Should().Be(string.Empty);
library.RuntimeAssemblyGroups[0].AssetPaths.Count.Should().Be(1);
library.RuntimeAssemblyGroups[0].AssetPaths[0].Should().Be($"{path}{dllName}.dll");

foreach (string locale in locales)
{
// Try to get the locale as part of a dependency package: Humanizer.Core.af
Expand All @@ -221,7 +221,7 @@ private static void VerifyDependency(
{
localeLibrary = library;
}

localeLibrary
.ResourceAssemblies
.FirstOrDefault(r => r.Locale == locale && r.Path == $"{path}{locale}/{dllName}.resources.dll")
Expand Down