Skip to content

Commit

Permalink
Generate appconfig for full framework project
Browse files Browse the repository at this point in the history
  • Loading branch information
William Li committed Jul 31, 2018
1 parent 0a9ae1b commit afd4b55
Show file tree
Hide file tree
Showing 19 changed files with 555 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Tasks/Common/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,8 @@ The following are names of parameters or literal values and should not be transl
<value>NETSDK1069: This project uses a library that targets .NET Standard 1.5 or higher, and the project targets a version of .NET Framework that doesn't have built-in support for that version of .NET Standard. Visit https://aka.ms/net-standard-known-issues for a set of known issues. Consider retargeting to .NET Framework 4.7.2.</value>
<comment>{StrBegin="NETSDK1069: "}</comment>
</data>
<data name="AppConfigRequiresRootConfiguration" xml:space="preserve">
<value>NETSDK1070: The application configuration file must have root configuration element.</value>
<comment>{StrBegin="NETSDK1070: "}</comment>
</data>
</root>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: Je potřeba zadat alespoň jednu možnou cílovou architekturu.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: Geben Sie mindestens ein mögliches Zielframework an.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: Debe especificarse al menos una plataforma de destino posible.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: Vous devez spécifier au moins un framework cible.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: è necessario specificare almeno un framework di destinazione possibile.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: 可能性のあるターゲット フレームワークを少なくとも 1 つ指定する必要があります。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: 가능한 대상 프레임워크를 하나 이상 지정해야 합니다.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: Należy określić co najmniej jedną możliwą platformę docelową.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: É necessário especificar pelo menos uma estrutura de destino possível.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: необходимо указать хотя бы одну целевую платформу.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: En az bir olası hedef çerçeve belirtilmelidir.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hans" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: 必须指定至少一个可能的目标框架。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hant" original="../Strings.resx">
<body>
<trans-unit id="AppConfigRequiresRootConfiguration">
<source>NETSDK1070: The application configuration file must have root configuration element.</source>
<target state="new">NETSDK1070: The application configuration file must have root configuration element.</target>
<note>{StrBegin="NETSDK1070: "}</note>
</trans-unit>
<trans-unit id="AtLeastOneTargetFrameworkMustBeSpecified">
<source>NETSDK1001: At least one possible target framework must be specified.</source>
<target state="translated">NETSDK1001: 至少必須指定一個可能的目標架構。</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using FluentAssertions;
using NuGet.Frameworks;
using System.Linq;
using System.Xml.Linq;
using Xunit;

namespace Microsoft.NET.Build.Tasks.UnitTests
{
public class GivenAGenerateAppConfig
{
[Fact]
public void It_creates_startup_and_supportedRuntime_nod_when_there_is_not_any()
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration"));

GenerateAppConfig.AddSupportedRuntimeToAppconfigFile(doc, "net452");

doc.Element("configuration")
.Elements("startup")
.Single().Elements()
.Should().Contain(e => e.Name.LocalName == "supportedRuntime");
}

[Fact]
public void It_creates_supportedRuntime_nod_when_there_is_startup()
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration", new XElement("startup")));

GenerateAppConfig.AddSupportedRuntimeToAppconfigFile(doc, "net452");

doc.Element("configuration")
.Elements("startup")
.Single().Elements()
.Should().Contain(e => e.Name.LocalName == "supportedRuntime");
}

[Fact]
public void It_does_not_change_supportedRuntime_nod_when_there_is_supportedRuntime()
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration",
new XElement("startup",
new XElement("supportedRuntime",
new XAttribute("version", "v4.0"),
new XAttribute("sku", ".NETFramework,Version=v4.7.2")))));

GenerateAppConfig.AddSupportedRuntimeToAppconfigFile(doc, "net461");

XElement supportedRuntime = doc.Element("configuration")
.Elements("startup")
.Single().Elements("supportedRuntime")
.Single();

supportedRuntime.Should().HaveAttribute("version", "v4.0");
supportedRuntime.Should().HaveAttribute("sku", ".NETFramework,Version=v4.7.2");
}

// intersection of https://docs.microsoft.com/en-us/nuget/reference/target-frameworks
// and https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/startup/supportedruntime-element#version
[Theory]
[InlineData("net11", "v1.1.4322")]
[InlineData("net20", "v2.0.50727")]
[InlineData("net35", "v2.0.50727")]
public void It_Generate_correct_version_and_sku_for_below40(string targetframework, string expectedVersion)
{
var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration"));

GenerateAppConfig.AddSupportedRuntimeToAppconfigFile(doc, targetframework);

XElement supportedRuntime = doc.Element("configuration")
.Elements("startup")
.Single().Elements("supportedRuntime")
.Single();

supportedRuntime.Should().HaveAttribute("version", expectedVersion);
supportedRuntime.Attribute("sku").Should().BeNull();
}

[Theory]
[InlineData("net45", "v4.0", ".NETFramework,Version=v4.5")]
[InlineData("net451", "v4.0", ".NETFramework,Version=v4.5.1")]
[InlineData("net452", "v4.0", ".NETFramework,Version=v4.5.2")]
[InlineData("net46", "v4.0", ".NETFramework,Version=v4.6")]
[InlineData("net461", "v4.0", ".NETFramework,Version=v4.6.1")]
[InlineData("net462", "v4.0", ".NETFramework,Version=v4.6.2")]
[InlineData("net47", "v4.0", ".NETFramework,Version=v4.7")]
[InlineData("net471", "v4.0", ".NETFramework,Version=v4.7.1")]
[InlineData("net472", "v4.0", ".NETFramework,Version=v4.7.2")]
public void It_Generate_correct_version_and_sku_for_above40(string targetframework, string expectedVersion, string expectedSku)
{
var targetFrameworkParsed = NuGetFramework.Parse(targetframework);

var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration"));

GenerateAppConfig.AddSupportedRuntimeToAppconfigFile(doc, targetframework);

XElement supportedRuntime = doc.Element("configuration")
.Elements("startup")
.Single().Elements("supportedRuntime")
.Single();

supportedRuntime.Should().HaveAttribute("version", expectedVersion);
supportedRuntime.Should().HaveAttribute("sku", expectedSku);
}

[Theory]
[InlineData("net10")]
[InlineData("net30")]
[InlineData("net999")]
[InlineData("netstandard20")]
public void It_does_not_generate_version_and_sku_for_non_supported(string targetframework)
{
var targetFrameworkParsed = NuGetFramework.Parse(targetframework);

var doc =
new XDocument(
new XDeclaration("1.0", "utf-8", "true"),
new XElement("configuration"));

GenerateAppConfig.AddSupportedRuntimeToAppconfigFile(doc, targetframework);

doc.Element("configuration")
.Elements("startup").Should().BeNullOrEmpty();
}
}
}
Loading

0 comments on commit afd4b55

Please sign in to comment.