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

This commit is contained in:
discostu105 2016-02-21 23:01:55 +01:00
parent be8cde81b2
commit ac3e14c89e
2 changed files with 24 additions and 6 deletions

View file

@ -59,8 +59,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
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(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)

View file

@ -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;
}