From ac3e14c89e51e1b15d2f33d3d0fdb9a842272d9b Mon Sep 17 00:00:00 2001 From: discostu105 Date: Sun, 21 Feb 2016 23:01:55 +0100 Subject: [PATCH 01/11] Added TargetFrameworkVersion to AssemblyInfoOptions in order to let AssemblyInfoFileGenerator if attributes are compatible with framework version. E.g. TargetFrameworkAttribute is not .NET 2.0 compatible. fixes #1480 --- .../AssemblyInfoFileGenerator.cs | 12 ++++++++---- .../AssemblyInfoOptions.cs | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs index ab24413fb..e93561d65 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs @@ -59,8 +59,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common private static Dictionary GetProjectAttributes(AssemblyInfoOptions metadata) { - return new Dictionary() - { + var attributes = new Dictionary() { [typeof(AssemblyTitleAttribute)] = EscapeCharacters(metadata.Title), [typeof(AssemblyDescriptionAttribute)] = EscapeCharacters(metadata.Description), [typeof(AssemblyCopyrightAttribute)] = EscapeCharacters(metadata.Copyright), @@ -68,9 +67,14 @@ namespace Microsoft.DotNet.Cli.Compiler.Common [typeof(AssemblyVersionAttribute)] = EscapeCharacters(metadata.AssemblyVersion?.ToString()), [typeof(AssemblyInformationalVersionAttribute)] = EscapeCharacters(metadata.InformationalVersion), [typeof(AssemblyCultureAttribute)] = EscapeCharacters(metadata.Culture), - [typeof(NeutralResourcesLanguageAttribute)] = EscapeCharacters(metadata.NeutralLanguage), - [typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework) + [typeof(NeutralResourcesLanguageAttribute)] = EscapeCharacters(metadata.NeutralLanguage) }; + + // only .net 4.0+ compatible + if (metadata.TargetFrameworkVersion == null || metadata.TargetFrameworkVersion >= new Version(4, 0)) { + attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework); + }; + return attributes; } private static bool IsSameAttribute(Type attributeType, AttributeSyntax attributeSyntax) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs index 0fe593c8d..5b66b520f 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs @@ -1,6 +1,7 @@ // 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 System; using Microsoft.DotNet.ProjectModel; using System.Collections.Generic; using System.CommandLine; @@ -28,6 +29,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common private const string TargetFrameworkOptionName = "target-framework"; + private const string TargetFrameworkVersionOptionName = "target-framework-version"; + public string Title { get; set; } public string Description { get; set; } @@ -46,6 +49,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common public string TargetFramework { get; set; } + public Version TargetFrameworkVersion { get; set; } + public static AssemblyInfoOptions CreateForProject(ProjectContext context) { var project = context.ProjectFile; @@ -69,7 +74,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common Description = project.Description, Title = project.Title, NeutralLanguage = project.Language, - TargetFramework = targetFramework.DotNetFrameworkName + TargetFramework = targetFramework.DotNetFrameworkName, + TargetFrameworkVersion = targetFramework.Version }; } @@ -84,6 +90,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common string culture = null; string neutralCulture = null; string targetFramework = null; + string targetFrameworkVersion = null; syntax.DefineOption(AssemblyVersionOptionName, ref version, UnescapeNewlines, "Assembly version"); @@ -103,6 +110,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common syntax.DefineOption(TargetFrameworkOptionName, ref targetFramework, UnescapeNewlines, "Assembly target framework"); + syntax.DefineOption(TargetFrameworkVersionOptionName, ref targetFrameworkVersion, UnescapeNewlines, "Assembly target framework version"); + return new AssemblyInfoOptions() { AssemblyFileVersion = fileVersion, @@ -112,7 +121,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common Description = description, InformationalVersion = informationalVersion, Title = title, - TargetFramework = targetFramework + TargetFramework = targetFramework, + TargetFrameworkVersion = new Version(targetFrameworkVersion) }; } @@ -156,6 +166,10 @@ namespace Microsoft.DotNet.Cli.Compiler.Common { options.Add(FormatOption(TargetFrameworkOptionName, assemblyInfoOptions.TargetFramework)); } + if (assemblyInfoOptions.TargetFrameworkVersion != null) + { + options.Add(FormatOption(TargetFrameworkVersionOptionName, assemblyInfoOptions.TargetFrameworkVersion.ToString())); + } return options; } From a31d4a7920839952d62f37e7e817a4a4b353747e Mon Sep 17 00:00:00 2001 From: discostu105 Date: Sun, 21 Feb 2016 23:38:13 +0100 Subject: [PATCH 02/11] fixed newlines --- .../AssemblyInfoFileGenerator.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs index e93561d65..45e3e9302 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs @@ -59,7 +59,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common private static Dictionary GetProjectAttributes(AssemblyInfoOptions metadata) { - var attributes = new Dictionary() { + var attributes = new Dictionary() + { [typeof(AssemblyTitleAttribute)] = EscapeCharacters(metadata.Title), [typeof(AssemblyDescriptionAttribute)] = EscapeCharacters(metadata.Description), [typeof(AssemblyCopyrightAttribute)] = EscapeCharacters(metadata.Copyright), @@ -71,7 +72,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common }; // only .net 4.0+ compatible - if (metadata.TargetFrameworkVersion == null || metadata.TargetFrameworkVersion >= new Version(4, 0)) { + if (metadata.TargetFrameworkVersion == null || metadata.TargetFrameworkVersion >= new Version(4, 0)) + { attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework); }; return attributes; @@ -89,4 +91,4 @@ namespace Microsoft.DotNet.Cli.Compiler.Common return str != null ? SymbolDisplay.FormatLiteral(str, quote: false) : null; } } -} \ No newline at end of file +} From 5e574f46d8324a306fd067da8e9f1b9acf03fd21 Mon Sep 17 00:00:00 2001 From: discostu105 Date: Mon, 22 Feb 2016 09:57:55 +0100 Subject: [PATCH 03/11] using NuGetFramework.Parse instead of passing Version object --- .../AssemblyInfoFileGenerator.cs | 9 +++++++-- .../AssemblyInfoOptions.cs | 14 ++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs index e93561d65..ed93e3320 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs @@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.CSharp; using System.IO; using System.Runtime.Versioning; using Microsoft.CodeAnalysis.CSharp.Syntax; +using NuGet.Frameworks; namespace Microsoft.DotNet.Cli.Compiler.Common { @@ -59,7 +60,10 @@ namespace Microsoft.DotNet.Cli.Compiler.Common private static Dictionary GetProjectAttributes(AssemblyInfoOptions metadata) { - var attributes = new Dictionary() { + NuGetFramework targetFramework = NuGetFramework.Parse(metadata.TargetFramework); + + var attributes = new Dictionary() + { [typeof(AssemblyTitleAttribute)] = EscapeCharacters(metadata.Title), [typeof(AssemblyDescriptionAttribute)] = EscapeCharacters(metadata.Description), [typeof(AssemblyCopyrightAttribute)] = EscapeCharacters(metadata.Copyright), @@ -71,7 +75,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common }; // only .net 4.0+ compatible - if (metadata.TargetFrameworkVersion == null || metadata.TargetFrameworkVersion >= new Version(4, 0)) { + if (targetFramework.Version >= new Version(4, 0)) + { attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework); }; return attributes; diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs index 5b66b520f..c59ec0657 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs @@ -49,8 +49,6 @@ namespace Microsoft.DotNet.Cli.Compiler.Common public string TargetFramework { get; set; } - public Version TargetFrameworkVersion { get; set; } - public static AssemblyInfoOptions CreateForProject(ProjectContext context) { var project = context.ProjectFile; @@ -74,8 +72,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common Description = project.Description, Title = project.Title, NeutralLanguage = project.Language, - TargetFramework = targetFramework.DotNetFrameworkName, - TargetFrameworkVersion = targetFramework.Version + TargetFramework = targetFramework.DotNetFrameworkName }; } @@ -110,8 +107,6 @@ namespace Microsoft.DotNet.Cli.Compiler.Common syntax.DefineOption(TargetFrameworkOptionName, ref targetFramework, UnescapeNewlines, "Assembly target framework"); - syntax.DefineOption(TargetFrameworkVersionOptionName, ref targetFrameworkVersion, UnescapeNewlines, "Assembly target framework version"); - return new AssemblyInfoOptions() { AssemblyFileVersion = fileVersion, @@ -121,8 +116,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common Description = description, InformationalVersion = informationalVersion, Title = title, - TargetFramework = targetFramework, - TargetFrameworkVersion = new Version(targetFrameworkVersion) + TargetFramework = targetFramework }; } @@ -166,10 +160,6 @@ namespace Microsoft.DotNet.Cli.Compiler.Common { options.Add(FormatOption(TargetFrameworkOptionName, assemblyInfoOptions.TargetFramework)); } - if (assemblyInfoOptions.TargetFrameworkVersion != null) - { - options.Add(FormatOption(TargetFrameworkVersionOptionName, assemblyInfoOptions.TargetFrameworkVersion.ToString())); - } return options; } From e08401aed6a973b6b908c0c5a7bedc6c5de79eba Mon Sep 17 00:00:00 2001 From: discostu105 Date: Mon, 22 Feb 2016 10:53:01 +0100 Subject: [PATCH 04/11] handle case where TargetFramework is null --- .../AssemblyInfoFileGenerator.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs index ed93e3320..fce3d6db1 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs @@ -60,8 +60,6 @@ namespace Microsoft.DotNet.Cli.Compiler.Common private static Dictionary GetProjectAttributes(AssemblyInfoOptions metadata) { - NuGetFramework targetFramework = NuGetFramework.Parse(metadata.TargetFramework); - var attributes = new Dictionary() { [typeof(AssemblyTitleAttribute)] = EscapeCharacters(metadata.Title), @@ -74,10 +72,10 @@ namespace Microsoft.DotNet.Cli.Compiler.Common [typeof(NeutralResourcesLanguageAttribute)] = EscapeCharacters(metadata.NeutralLanguage) }; - // only .net 4.0+ compatible - if (targetFramework.Version >= new Version(4, 0)) + NuGetFramework targetFramework = string.IsNullOrEmpty(metadata.TargetFramework) ? null : NuGetFramework.Parse(metadata.TargetFramework); + if (targetFramework != null && !(targetFramework.IsDesktop() && targetFramework.Version < new Version(4, 0))) { - attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework); + attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework); // TargetFrameworkAttribute only exists since .NET 4.0 }; return attributes; } From 8dc1e94aa92c16b75c0096bf038977a47060061b Mon Sep 17 00:00:00 2001 From: discostu105 Date: Mon, 22 Feb 2016 11:22:26 +0100 Subject: [PATCH 05/11] cleanup in AssemblyInfoOptions --- src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs index c59ec0657..276c42bf7 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs @@ -29,8 +29,6 @@ namespace Microsoft.DotNet.Cli.Compiler.Common private const string TargetFrameworkOptionName = "target-framework"; - private const string TargetFrameworkVersionOptionName = "target-framework-version"; - public string Title { get; set; } public string Description { get; set; } @@ -87,7 +85,6 @@ namespace Microsoft.DotNet.Cli.Compiler.Common string culture = null; string neutralCulture = null; string targetFramework = null; - string targetFrameworkVersion = null; syntax.DefineOption(AssemblyVersionOptionName, ref version, UnescapeNewlines, "Assembly version"); From f0c8428925b3be56689ef57c814b525a3a9dee28 Mon Sep 17 00:00:00 2001 From: discostu105 Date: Mon, 22 Feb 2016 11:25:02 +0100 Subject: [PATCH 06/11] cleanup of AssemblyInfoOptions --- src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs index 276c42bf7..0fe593c8d 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoOptions.cs @@ -1,7 +1,6 @@ // 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 System; using Microsoft.DotNet.ProjectModel; using System.Collections.Generic; using System.CommandLine; From d0d3a629a521772cc23d497fd6c9d866a3432885 Mon Sep 17 00:00:00 2001 From: discostu105 Date: Tue, 23 Feb 2016 15:53:51 +0100 Subject: [PATCH 07/11] added unit test. made if condition easier to understand. --- .../Program.cs | 12 ++++++++ .../project.json | 20 +++++++++++++ .../AssemblyInfoFileGenerator.cs | 24 +++++++++++++-- test/dotnet-build.Tests/BuildOutputTests.cs | 30 +++++++++++++++++++ 4 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 TestAssets/TestProjects/TestLibraryWithMultipleFrameworks/Program.cs create mode 100644 TestAssets/TestProjects/TestLibraryWithMultipleFrameworks/project.json diff --git a/TestAssets/TestProjects/TestLibraryWithMultipleFrameworks/Program.cs b/TestAssets/TestProjects/TestLibraryWithMultipleFrameworks/Program.cs new file mode 100644 index 000000000..f5f4b6d13 --- /dev/null +++ b/TestAssets/TestProjects/TestLibraryWithMultipleFrameworks/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main() + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/TestAssets/TestProjects/TestLibraryWithMultipleFrameworks/project.json b/TestAssets/TestProjects/TestLibraryWithMultipleFrameworks/project.json new file mode 100644 index 000000000..4d87acf96 --- /dev/null +++ b/TestAssets/TestProjects/TestLibraryWithMultipleFrameworks/project.json @@ -0,0 +1,20 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": false + }, + + "dependencies": { }, + + "frameworks": { + "net20": { }, + "net35": { }, + "net40": { }, + "net461": { }, + "dnxcore50": { + "dependencies": { + "NETStandard.Library": "1.0.0-rc2-23811" + } + } + } +} diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs index fce3d6db1..96c217e65 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs @@ -71,15 +71,33 @@ namespace Microsoft.DotNet.Cli.Compiler.Common [typeof(AssemblyCultureAttribute)] = EscapeCharacters(metadata.Culture), [typeof(NeutralResourcesLanguageAttribute)] = EscapeCharacters(metadata.NeutralLanguage) }; - - NuGetFramework targetFramework = string.IsNullOrEmpty(metadata.TargetFramework) ? null : NuGetFramework.Parse(metadata.TargetFramework); - if (targetFramework != null && !(targetFramework.IsDesktop() && targetFramework.Version < new Version(4, 0))) + + if (IsAllowV4Attributes(metadata)) { attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework); // TargetFrameworkAttribute only exists since .NET 4.0 }; + return attributes; } + private static bool IsAllowV4Attributes(AssemblyInfoOptions metadata) + { + if (string.IsNullOrEmpty(metadata.TargetFramework)) + { + // target framework is unknown. to be on the safe side, return false. + return false; + } + + NuGetFramework targetFramework = NuGetFramework.Parse(metadata.TargetFramework); + if (!targetFramework.IsDesktop()) + { + // assuming .NET Core, which should support .NET 4.0 attributes + return true; + } + + return targetFramework.Version >= new Version(4, 0); + } + private static bool IsSameAttribute(Type attributeType, AttributeSyntax attributeSyntax) { var name = attributeSyntax.Name.ToString(); diff --git a/test/dotnet-build.Tests/BuildOutputTests.cs b/test/dotnet-build.Tests/BuildOutputTests.cs index 1f4a702a8..f91970125 100644 --- a/test/dotnet-build.Tests/BuildOutputTests.cs +++ b/test/dotnet-build.Tests/BuildOutputTests.cs @@ -7,6 +7,7 @@ using FluentAssertions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.Extensions.PlatformAbstractions; +using NuGet.Frameworks; using Xunit; namespace Microsoft.DotNet.Tools.Builder.Tests @@ -128,6 +129,35 @@ namespace Microsoft.DotNet.Tools.Builder.Tests informationalVersion.Should().BeEquivalentTo("1.0.0-85"); } + [Theory] + [InlineData("net20", false)] + [InlineData("net40", true)] + [InlineData("net461", true)] + [InlineData("dnxcore50", true)] + public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute) + { + var framework = NuGetFramework.Parse(frameworkName); + + var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithMultipleFrameworks") + .WithLockFiles(); + + var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: framework.GetShortFolderName()); + cmd.ExecuteWithCapturedOutput().Should().Pass(); + + var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", framework.GetShortFolderName(), "TestLibraryWithMultipleFrameworks.dll"); + var targetFramework = PeReaderUtils.GetAssemblyAttributeValue(output, "TargetFrameworkAttribute"); + + if (shouldHaveTargetFrameworkAttribute) + { + targetFramework.Should().NotBeNull(); + targetFramework.Should().BeEquivalentTo(framework.DotNetFrameworkName); + } + else + { + targetFramework.Should().BeNull(); + } + } + [Fact] public void ResourceTest() { From ccb3d06f23b5a22a95889f8f656996447760f271 Mon Sep 17 00:00:00 2001 From: discostu105 Date: Tue, 23 Feb 2016 17:10:00 +0100 Subject: [PATCH 08/11] changed method name as suggested by david --- .../AssemblyInfoFileGenerator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs index 96c217e65..5f36f2d5c 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs @@ -72,7 +72,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common [typeof(NeutralResourcesLanguageAttribute)] = EscapeCharacters(metadata.NeutralLanguage) }; - if (IsAllowV4Attributes(metadata)) + if (SupportsTargetFrameworkAttribute(metadata)) { attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework); // TargetFrameworkAttribute only exists since .NET 4.0 }; @@ -80,7 +80,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common return attributes; } - private static bool IsAllowV4Attributes(AssemblyInfoOptions metadata) + private static bool SupportsTargetFrameworkAttribute(AssemblyInfoOptions metadata) { if (string.IsNullOrEmpty(metadata.TargetFramework)) { From ceb31d8f30f39709a2bcd0a3a30bf81dda34a7e8 Mon Sep 17 00:00:00 2001 From: discostu105 Date: Tue, 23 Feb 2016 17:28:50 +0100 Subject: [PATCH 09/11] styling --- .../AssemblyInfoFileGenerator.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs index 5f36f2d5c..3e4408bc8 100644 --- a/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs +++ b/src/Microsoft.DotNet.Compiler.Common/AssemblyInfoFileGenerator.cs @@ -74,7 +74,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common if (SupportsTargetFrameworkAttribute(metadata)) { - attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework); // TargetFrameworkAttribute only exists since .NET 4.0 + // TargetFrameworkAttribute only exists since .NET 4.0 + attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework); }; return attributes; @@ -88,7 +89,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common return false; } - NuGetFramework targetFramework = NuGetFramework.Parse(metadata.TargetFramework); + var targetFramework = NuGetFramework.Parse(metadata.TargetFramework); if (!targetFramework.IsDesktop()) { // assuming .NET Core, which should support .NET 4.0 attributes From 5ad60df96aca9d84719179ba5f4941fcfc6a8c67 Mon Sep 17 00:00:00 2001 From: discostu105 Date: Tue, 23 Feb 2016 18:03:04 +0100 Subject: [PATCH 10/11] don't compile desktop framework targets on non-windows --- test/dotnet-build.Tests/BuildOutputTests.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/dotnet-build.Tests/BuildOutputTests.cs b/test/dotnet-build.Tests/BuildOutputTests.cs index f91970125..71062f58b 100644 --- a/test/dotnet-build.Tests/BuildOutputTests.cs +++ b/test/dotnet-build.Tests/BuildOutputTests.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; +using System.Runtime.InteropServices; using FluentAssertions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; @@ -130,12 +131,17 @@ namespace Microsoft.DotNet.Tools.Builder.Tests } [Theory] - [InlineData("net20", false)] - [InlineData("net40", true)] - [InlineData("net461", true)] - [InlineData("dnxcore50", true)] - public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute) + [InlineData("net20", false, true)] + [InlineData("net40", true, true)] + [InlineData("net461", true, true)] + [InlineData("dnxcore50", true, false)] + public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute, bool windowsOnly) { + if (windowsOnly && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return; // don't run test for desktop framework on non-windows + } + var framework = NuGetFramework.Parse(frameworkName); var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithMultipleFrameworks") From af5aaea6d0feb6cdedd515051d39a49ea62b8641 Mon Sep 17 00:00:00 2001 From: discostu105 Date: Wed, 24 Feb 2016 14:19:21 +0100 Subject: [PATCH 11/11] assert on Should().Fail() on non-windows platforms for desktop frameworks --- test/dotnet-build.Tests/BuildOutputTests.cs | 30 ++++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/test/dotnet-build.Tests/BuildOutputTests.cs b/test/dotnet-build.Tests/BuildOutputTests.cs index 71062f58b..6917e83fc 100644 --- a/test/dotnet-build.Tests/BuildOutputTests.cs +++ b/test/dotnet-build.Tests/BuildOutputTests.cs @@ -137,30 +137,34 @@ namespace Microsoft.DotNet.Tools.Builder.Tests [InlineData("dnxcore50", true, false)] public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute, bool windowsOnly) { - if (windowsOnly && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return; // don't run test for desktop framework on non-windows - } - var framework = NuGetFramework.Parse(frameworkName); var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithMultipleFrameworks") .WithLockFiles(); var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: framework.GetShortFolderName()); - cmd.ExecuteWithCapturedOutput().Should().Pass(); - var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", framework.GetShortFolderName(), "TestLibraryWithMultipleFrameworks.dll"); - var targetFramework = PeReaderUtils.GetAssemblyAttributeValue(output, "TargetFrameworkAttribute"); - - if (shouldHaveTargetFrameworkAttribute) + if (windowsOnly && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - targetFramework.Should().NotBeNull(); - targetFramework.Should().BeEquivalentTo(framework.DotNetFrameworkName); + // on non-windows platforms, desktop frameworks will not build + cmd.ExecuteWithCapturedOutput().Should().Fail(); } else { - targetFramework.Should().BeNull(); + cmd.ExecuteWithCapturedOutput().Should().Pass(); + + var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", framework.GetShortFolderName(), "TestLibraryWithMultipleFrameworks.dll"); + var targetFramework = PeReaderUtils.GetAssemblyAttributeValue(output, "TargetFrameworkAttribute"); + + if (shouldHaveTargetFrameworkAttribute) + { + targetFramework.Should().NotBeNull(); + targetFramework.Should().BeEquivalentTo(framework.DotNetFrameworkName); + } + else + { + targetFramework.Should().BeNull(); + } } }