Merge pull request #1513 from discostu105/rel/1.0.0
Fix net20 compatibility
This commit is contained in:
commit
6dc5efb0e2
4 changed files with 101 additions and 3 deletions
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ConsoleApplication
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ using Microsoft.CodeAnalysis.CSharp;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||||
|
using NuGet.Frameworks;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Compiler.Common
|
namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
{
|
{
|
||||||
|
@ -59,7 +60,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
|
|
||||||
private static Dictionary<Type, string> GetProjectAttributes(AssemblyInfoOptions metadata)
|
private static Dictionary<Type, string> GetProjectAttributes(AssemblyInfoOptions metadata)
|
||||||
{
|
{
|
||||||
return new Dictionary<Type, string>()
|
var attributes = new Dictionary<Type, string>()
|
||||||
{
|
{
|
||||||
[typeof(AssemblyTitleAttribute)] = EscapeCharacters(metadata.Title),
|
[typeof(AssemblyTitleAttribute)] = EscapeCharacters(metadata.Title),
|
||||||
[typeof(AssemblyDescriptionAttribute)] = EscapeCharacters(metadata.Description),
|
[typeof(AssemblyDescriptionAttribute)] = EscapeCharacters(metadata.Description),
|
||||||
|
@ -68,9 +69,34 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
[typeof(AssemblyVersionAttribute)] = EscapeCharacters(metadata.AssemblyVersion?.ToString()),
|
[typeof(AssemblyVersionAttribute)] = EscapeCharacters(metadata.AssemblyVersion?.ToString()),
|
||||||
[typeof(AssemblyInformationalVersionAttribute)] = EscapeCharacters(metadata.InformationalVersion),
|
[typeof(AssemblyInformationalVersionAttribute)] = EscapeCharacters(metadata.InformationalVersion),
|
||||||
[typeof(AssemblyCultureAttribute)] = EscapeCharacters(metadata.Culture),
|
[typeof(AssemblyCultureAttribute)] = EscapeCharacters(metadata.Culture),
|
||||||
[typeof(NeutralResourcesLanguageAttribute)] = EscapeCharacters(metadata.NeutralLanguage),
|
[typeof(NeutralResourcesLanguageAttribute)] = EscapeCharacters(metadata.NeutralLanguage)
|
||||||
[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (SupportsTargetFrameworkAttribute(metadata))
|
||||||
|
{
|
||||||
|
// TargetFrameworkAttribute only exists since .NET 4.0
|
||||||
|
attributes[typeof(TargetFrameworkAttribute)] = EscapeCharacters(metadata.TargetFramework);
|
||||||
|
};
|
||||||
|
|
||||||
|
return attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool SupportsTargetFrameworkAttribute(AssemblyInfoOptions metadata)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(metadata.TargetFramework))
|
||||||
|
{
|
||||||
|
// target framework is unknown. to be on the safe side, return false.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var 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)
|
private static bool IsSameAttribute(Type attributeType, AttributeSyntax attributeSyntax)
|
||||||
|
|
|
@ -3,10 +3,12 @@
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
|
using NuGet.Frameworks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Builder.Tests
|
namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||||
|
@ -128,6 +130,44 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||||
informationalVersion.Should().BeEquivalentTo("1.0.0-85");
|
informationalVersion.Should().BeEquivalentTo("1.0.0-85");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[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)
|
||||||
|
{
|
||||||
|
var framework = NuGetFramework.Parse(frameworkName);
|
||||||
|
|
||||||
|
var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithMultipleFrameworks")
|
||||||
|
.WithLockFiles();
|
||||||
|
|
||||||
|
var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: framework.GetShortFolderName());
|
||||||
|
|
||||||
|
if (windowsOnly && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
{
|
||||||
|
// on non-windows platforms, desktop frameworks will not build
|
||||||
|
cmd.ExecuteWithCapturedOutput().Should().Fail();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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]
|
[Fact]
|
||||||
public void ResourceTest()
|
public void ResourceTest()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue