-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change "assembly version to be used" to also respect AssemblyInformat…
…ionalVersionAttribute fixes #99
- Loading branch information
1 parent
deb74f5
commit 24a8755
Showing
7 changed files
with
84 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
AssemblyToProcess/ClassWithIsErrorFromInformationalVersion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ObsoleteEx( | ||
TreatAsErrorFromVersion = "1.0.1", | ||
RemoveInVersion = "1.1")] | ||
public class ClassWithIsErrorFromInformationalVersion | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Linq; | ||
using Mono.Cecil; | ||
|
||
static class VersionReader | ||
{ | ||
public static SemanticVersion Read(AssemblyDefinition assembly) | ||
{ | ||
var informationalAttribute = assembly.CustomAttributes | ||
.SingleOrDefault(x => x.AttributeType.FullName == "System.Reflection.AssemblyInformationalVersionAttribute"); | ||
if (informationalAttribute != null) | ||
{ | ||
var value = (string)informationalAttribute.ConstructorArguments.Single().Value; | ||
var indexOf = value.IndexOf(x => x != '.' && !char.IsNumber(x)); | ||
if (indexOf != -1) | ||
{ | ||
var substring = value.Substring(0, indexOf); | ||
if (SemanticVersion.TryParse(substring, out var versionFromInformational)) | ||
{ | ||
return versionFromInformational; | ||
} | ||
} | ||
} | ||
|
||
var version = assembly.Name.Version; | ||
var semanticVersion = new SemanticVersion | ||
{ | ||
Major = version.Major.OrZero(), | ||
Minor = version.Minor.OrZero(), | ||
Patch = version.Build.OrZero() | ||
}; | ||
return semanticVersion; | ||
} | ||
|
||
static int IndexOf(this string source, Func<char, bool> predicate) | ||
{ | ||
for (var index = 0; index < source.Length; index++) | ||
{ | ||
var item = source[index]; | ||
if (predicate.Invoke(item)) | ||
{ | ||
return index; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters