Skip to content

Assembly info patch for console #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo on

set framework=v4.0.30319

"%~dp0.nuget\nuget.exe" restore

"%SystemDrive%\Windows\Microsoft.NET\Framework\%framework%\MSBuild.exe" "%~dp0GitVersion.sln"

mkdir "%~dp0GitVersion\bin\Intermediate"
cp "%~dp0GitVersion\bin\Debug\GitVersion.exe" "%~dp0GitVersion\bin\Intermediate\GitVersion.exe"

"%~dp0GitVersion\bin\Intermediate\GitVersion.exe" /l console /output buildserver /updateAssemblyInfo /proj "%~dp0GitVersion.sln"
9 changes: 0 additions & 9 deletions CommonAssemblyInfo.cs

This file was deleted.

43 changes: 25 additions & 18 deletions GitVersionCore/ArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static ArgumentParser()

public static Arguments ParseArguments(string commandLineArguments)
{
return ParseArguments(commandLineArguments.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries).ToList());
return ParseArguments(commandLineArguments.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList());
}

public static Arguments ParseArguments(List<string> commandLineArguments)
Expand Down Expand Up @@ -59,12 +59,10 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
namedArguments = commandLineArguments.Skip(1).ToList();
}

EnsureArgumentsEvenCount(commandLineArguments, namedArguments);

for (var index = 0; index < namedArguments.Count; index = index+2)
for (var index = 0; index < namedArguments.Count; index = index + 2)
{
var name = namedArguments[index];
var value = namedArguments[index + 1];
var value = namedArguments.Count > index + 1 ? namedArguments[index + 1] : null;

if (IsSwitch("l", name))
{
Expand Down Expand Up @@ -120,6 +118,24 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
continue;
}

if (IsSwitch("updateAssemblyInfo", name))
{
if (new[] { "1", "true" }.Contains(value))
{
arguments.UpdateAssemblyInfo = true;
}
else if (new[] { "0", "false" }.Contains(value))
{
arguments.UpdateAssemblyInfo = false;
}
else
{
arguments.UpdateAssemblyInfo = true;
index--;
}
continue;
}

if ((IsSwitch("v", name)) && VersionParts.Contains(value.ToLower()))
{
arguments.VersionPart = value.ToLower();
Expand All @@ -128,7 +144,7 @@ public static Arguments ParseArguments(List<string> commandLineArguments)

if (IsSwitch("output", name))
{
var outputType = OutputType.Json;
OutputType outputType;
if (!Enum.TryParse(value, true, out outputType))
{
throw new ErrorException(string.Format("Value '{0}' cannot be parsed as output type, please use 'json' or 'buildserver'", value));
Expand Down Expand Up @@ -158,20 +174,11 @@ static bool IsSwitch(string switchName, string value)
return (string.Equals(switchName, value, StringComparison.InvariantCultureIgnoreCase));
}

static void EnsureArgumentsEvenCount(List<string> commandLineArguments, List<string> namedArguments)
{
if (namedArguments.Count.IsOdd())
{
var message = string.Format("Could not parse arguments: '{0}'.", string.Join(" ", commandLineArguments));
throw new ErrorException(message);
}
}

static bool IsHelp(string singleArgument)
{
return (singleArgument == "?") ||
IsSwitch("h", singleArgument) ||
IsSwitch("help", singleArgument) ||
return (singleArgument == "?") ||
IsSwitch("h", singleArgument) ||
IsSwitch("help", singleArgument) ||
IsSwitch("?", singleArgument);
}

Expand Down
9 changes: 2 additions & 7 deletions GitVersionCore/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ namespace GitVersion
{
using System;

public enum OutputType
{
BuildServer,

Json
}

public class Arguments
{
public Arguments()
Expand Down Expand Up @@ -36,5 +29,7 @@ public Arguments()
public string ProjArgs;
public string Exec;
public string ExecArgs;

public bool UpdateAssemblyInfo;
}
}
10 changes: 10 additions & 0 deletions GitVersionCore/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace GitVersion
{
using System;
using System.Text;
using System.Text.RegularExpressions;
using JetBrains.Annotations;

static class ExtensionMethods
Expand All @@ -18,12 +19,14 @@ public static string TrimToFirstLine(this string s)
"\n"
}, StringSplitOptions.None)[0];
}

[StringFormatMethod("format")]
public static void AppendLineFormat(this StringBuilder stringBuilder, string format, params object[] args)
{
stringBuilder.AppendFormat(format, args);
stringBuilder.AppendLine();
}

public static string TrimStart(this string value, string toTrim)
{
if (!value.StartsWith(toTrim))
Expand All @@ -34,6 +37,7 @@ public static string TrimStart(this string value, string toTrim)
return value.Substring(startIndex);
}


public static string JsonEncode(this string value)
{
if (value != null)
Expand All @@ -49,5 +53,11 @@ public static string JsonEncode(this string value)
}
return null;
}

public static string RegexReplace(this string input, string pattern, string replace, RegexOptions options = RegexOptions.None)
{
return Regex.Replace(input, pattern, replace, options);
}

}
}
2 changes: 1 addition & 1 deletion GitVersionCore/GitHubFlow/GitHubFlowVersionFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class GitHubFlowVersionFinder
public SemanticVersion FindVersion(GitVersionContext context)
{
var repositoryDirectory = context.Repository.Info.WorkingDirectory;
var lastTaggedReleaseFinder = new LastTaggedReleaseFinder(context.Repository, repositoryDirectory);
var lastTaggedReleaseFinder = new LastTaggedReleaseFinder(context.Repository);
return new BuildNumberCalculator(new NextSemverCalculator(new NextVersionTxtFileFinder(repositoryDirectory),
lastTaggedReleaseFinder), lastTaggedReleaseFinder, context.Repository).GetBuildNumber(context);
}
Expand Down
10 changes: 1 addition & 9 deletions GitVersionCore/GitHubFlow/LastTaggedReleaseFinder.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
namespace GitVersion
{
using System;
using System.IO;
using System.Linq;
using LibGit2Sharp;

public class LastTaggedReleaseFinder
{
string workingDirectory;
Lazy<VersionTaggedCommit> lastTaggedRelease;

public LastTaggedReleaseFinder(IRepository gitRepo, string workingDirectory)
public LastTaggedReleaseFinder(IRepository gitRepo)
{
this.workingDirectory = workingDirectory;
lastTaggedRelease = new Lazy<VersionTaggedCommit>(() => GetVersion(gitRepo));
}

Expand Down Expand Up @@ -42,11 +39,6 @@ VersionTaggedCommit GetVersion(IRepository gitRepo)
if (lastTaggedCommit != null)
return tags.Last(a => a.Commit.Sha == lastTaggedCommit.Sha);

// Create a next version txt as 0.1.0
var filePath = Path.Combine(workingDirectory, "NextVersion.txt");
if (!File.Exists(filePath))
File.WriteAllText(filePath, "0.1.0");

var commit = branch.Commits.Last();
return new VersionTaggedCommit(commit, new SemanticVersion());
}
Expand Down
5 changes: 2 additions & 3 deletions GitVersionCore/GitVersionCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
<Link>CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="ArgumentParser.cs" />
<Compile Include="Arguments.cs" />
<Compile Include="BuildServers\AppVeyor.cs" />
Expand Down Expand Up @@ -96,8 +93,10 @@
<Compile Include="MissingBranchException.cs" />
<Compile Include="OutputFormatters\BuildOutputFormatter.cs" />
<Compile Include="OutputFormatters\JsonOutputFormatter.cs" />
<Compile Include="OutputType.cs" />
<Compile Include="OutputVariables\CiFeedFormatter.cs" />
<Compile Include="OutputVariables\VariableProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReleaseDate.cs" />
<Compile Include="ReleaseDateFinder.cs" />
<Compile Include="RepositoryLoader.cs" />
Expand Down
24 changes: 24 additions & 0 deletions GitVersionCore/GitVersionCore.v2.ncrunchproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<AllowCodeAnalysis>false</AllowCodeAnalysis>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<DetectStackOverflow>true</DetectStackOverflow>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
<MSTestThreadApartmentState>STA</MSTestThreadApartmentState>
<BuildProcessArchitecture>x86</BuildProcessArchitecture>
</ProjectConfiguration>
9 changes: 9 additions & 0 deletions GitVersionCore/OutputType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GitVersion
{
public enum OutputType
{
BuildServer,

Json
}
}
14 changes: 14 additions & 0 deletions GitVersionCore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyTitle("GitVersionCore")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyProduct("GitVersion")]

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

[assembly: InternalsVisibleTo("Tests")]
[assembly: InternalsVisibleTo("GitVersion")]
[assembly: InternalsVisibleTo("AcceptanceTests")]
68 changes: 68 additions & 0 deletions GitVersionExe/AssemblyInfoFileUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace GitVersion
{
using System;
using System.Collections.Generic;
using System.IO;

internal class AssemblyInfoFileUpdate : IDisposable
{
private readonly List<Action> _restoreBackupTasks = new List<Action>();
private readonly List<Action> _cleanupBackupTasks = new List<Action>();

public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, Dictionary<string, string> variables)
{
if (!args.UpdateAssemblyInfo) return;

if (args.Output != OutputType.Json)
Console.WriteLine("Updating assembly info files");

var assemblyInfoFiles = Directory.GetFiles(workingDirectory, "AssemblyInfo.cs",
SearchOption.AllDirectories);

foreach (var assemblyInfoFile in assemblyInfoFiles)
{
var backupAssemblyInfo = assemblyInfoFile + ".bak";
var localAssemblyInfo = assemblyInfoFile;
File.Copy(assemblyInfoFile, backupAssemblyInfo, true);
_restoreBackupTasks.Add(() =>
{
if (File.Exists(localAssemblyInfo))
File.Delete(localAssemblyInfo);
File.Move(backupAssemblyInfo, localAssemblyInfo);
});
_cleanupBackupTasks.Add(() => File.Delete(backupAssemblyInfo));

var assemblyVersion = string.Format("{0}.{1}.0.0", variables[VariableProvider.Major], variables[VariableProvider.Minor]);
var assemblyInfoVersion = variables[VariableProvider.InformationalVersion];
var assemblyFileVersion = variables[VariableProvider.AssemblySemVer];
var fileContents = File.ReadAllText(assemblyInfoFile)
.RegexReplace(@"AssemblyVersion\(""\d+.\d+.\d+(.\d+|\*)?""\)", string.Format("AssemblyVersion(\"{0}\")", assemblyVersion))
.RegexReplace(@"AssemblyInformationalVersion\(""\d+.\d+.\d+(.\d+|\*)?""\)", string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion))
.RegexReplace(@"AssemblyFileVersion\(""\d+.\d+.\d+(.\d+|\*)?""\)", string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion));

File.WriteAllText(assemblyInfoFile, fileContents);
}
}

public void Dispose()
{
foreach (var restoreBackup in _restoreBackupTasks)
{
restoreBackup();
}

_cleanupBackupTasks.Clear();
_restoreBackupTasks.Clear();
}

public void DoNotRestoreAssemblyInfo()
{
foreach (var cleanupBackupTask in _cleanupBackupTasks)
{
cleanupBackupTask();
}
_cleanupBackupTasks.Clear();
_restoreBackupTasks.Clear();
}
}
}
3 changes: 2 additions & 1 deletion GitVersionExe/GitVersionExe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@
<Compile Include="GitPreparer.cs" />
<Compile Include="HelpWriter.cs" />
<Compile Include="ProcessHelper.cs" />
<Compile Include="..\CommonAssemblyInfo.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AssemblyInfoFileUpdate.cs" />
</ItemGroup>
<ItemGroup>
<None Include="GemAssets\gitversion" />
Expand Down
24 changes: 24 additions & 0 deletions GitVersionExe/GitVersionExe.v2.ncrunchproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
<ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<PreloadReferencedAssemblies>false</PreloadReferencedAssemblies>
<AllowDynamicCodeContractChecking>true</AllowDynamicCodeContractChecking>
<AllowStaticCodeContractChecking>false</AllowStaticCodeContractChecking>
<AllowCodeAnalysis>false</AllowCodeAnalysis>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
<PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<DetectStackOverflow>true</DetectStackOverflow>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
<UseBuildConfiguration />
<UseBuildPlatform />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
<MSTestThreadApartmentState>STA</MSTestThreadApartmentState>
<BuildProcessArchitecture>x86</BuildProcessArchitecture>
</ProjectConfiguration>
Loading