Skip to content

Commit a45e2dc

Browse files
committed
re #630 - optionally allows /updateassemblyinfofilename to be generated
Adds argument /ensureassemblyinfo, when specified and /updateassemblyinfofilename is specified and does not exist we will generate a template of the assembly info file containing only *Version attributes in either cs, fs, vb allowing the version values to be replaced
1 parent d6289ba commit a45e2dc

13 files changed

+428
-7
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace GitVersionCore.Extensions
2+
{
3+
using System.IO;
4+
5+
public static class ReadEmbeddedResourceExtensions
6+
{
7+
/// <summary>
8+
///
9+
/// </summary>
10+
/// <typeparam name="T"></typeparam>
11+
/// <param name="resourceName">Should include Namespace separated path to resource in assembly referenced by <typeparamref name="T"/></param>
12+
/// <returns></returns>
13+
public static string ReadAsStringFromEmbeddedResource<T>(this string resourceName)
14+
{
15+
using (var stream = resourceName.ReadFromEmbeddedResource<T>())
16+
{
17+
using (var rdr = new StreamReader(stream))
18+
{
19+
return rdr.ReadToEnd();
20+
}
21+
}
22+
}
23+
24+
public static Stream ReadFromEmbeddedResource<T>(this string resourceName)
25+
{
26+
var assembly = typeof(T).Assembly;
27+
return assembly.GetManifestResourceStream(resourceName);
28+
}
29+
}
30+
}

src/GitVersionCore/GitVersionCore.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<Compile Include="Configuration\Init\StepResult.cs" />
110110
<Compile Include="EffectiveConfiguration.cs" />
111111
<Compile Include="ExecuteCore.cs" />
112+
<Compile Include="Extensions\ReadEmbeddedResourceExtensions.cs" />
112113
<Compile Include="GitPreparer.cs" />
113114
<Compile Include="GitVersionCache.cs" />
114115
<Compile Include="Helpers\FileSystem.cs" />
@@ -121,6 +122,8 @@
121122
<Compile Include="SemanticVersionExtensions.cs" />
122123
<Compile Include="SemanticVersionFormatValues.cs" />
123124
<Compile Include="StringFormatWith.cs" />
125+
<Compile Include="VersionAssemblyInfoResources\AssemblyVersionInfoTemplates.cs" />
126+
<EmbeddedResource Include="VersionAssemblyInfoResources\VersionAssemblyInfo.cs" />
124127
<Compile Include="VersionCalculation\BaseVersionCalculator.cs" />
125128
<Compile Include="VersionCalculation\BaseVersionCalculators\BaseVersion.cs" />
126129
<Compile Include="VersionCalculation\BaseVersionCalculators\ConfigNextVersionBaseVersionStrategy.cs" />
@@ -161,6 +164,8 @@
161164
<Content Include="FodyWeavers.xml">
162165
<SubType>Designer</SubType>
163166
</Content>
167+
<EmbeddedResource Include="VersionAssemblyInfoResources\VersionAssemblyInfo.vb" />
168+
<EmbeddedResource Include="VersionAssemblyInfoResources\VersionAssemblyInfo.fs" />
164169
</ItemGroup>
165170
<ItemGroup>
166171
<None Include="NugetAssets\GitVersion.nuspec">
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace GitVersion.VersionAssemblyInfoResources
2+
{
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using GitVersionCore.Extensions;
7+
8+
public class AssemblyVersionInfoTemplates
9+
{
10+
static IDictionary<string, FileInfo> assemblyInfoSourceList;
11+
12+
static AssemblyVersionInfoTemplates()
13+
{
14+
var enclosingNamespace = typeof(AssemblyVersionInfoTemplates).Namespace;
15+
16+
var files = typeof(AssemblyVersionInfoTemplates)
17+
.Assembly
18+
.GetManifestResourceNames()
19+
.Where(n => n.StartsWith(enclosingNamespace ?? string.Empty)).Select(f => new FileInfo(f));
20+
21+
assemblyInfoSourceList = files.ToDictionary(k => k.Extension, v => v);
22+
}
23+
24+
public static string GetAssemblyInfoTemplateFor(string assemblyInfoFile)
25+
{
26+
var fi = new FileInfo(assemblyInfoFile);
27+
if (assemblyInfoSourceList.ContainsKey(fi.Extension))
28+
{
29+
var template = assemblyInfoSourceList[fi.Extension];
30+
if (template != null)
31+
{
32+
return template.Name.ReadAsStringFromEmbeddedResource<AssemblyVersionInfoTemplates>();
33+
}
34+
}
35+
return null;
36+
}
37+
}
38+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by GitVersion.
4+
//
5+
// You can modify this code as we will not overwrite it when re-executing GitVersion
6+
// </auto-generated>
7+
//------------------------------------------------------------------------------
8+
9+
using System.Reflection;
10+
11+
[assembly: AssemblyFileVersion("0.0.0.0")]
12+
[assembly: AssemblyVersion("0.0.0.0")]
13+
[assembly: AssemblyInformationalVersion("0.0.0.0")]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by GitVersion.
4+
//
5+
// You can modify this code as we will not overwrite it when re-executing GitVersion
6+
// </auto-generated>
7+
//------------------------------------------------------------------------------
8+
9+
open System.Reflection
10+
11+
[<assembly: AssemblyFileVersion("0.0.0.0")>]
12+
[<assembly: AssemblyVersion("0.0.0.0")>]
13+
[<assembly: AssemblyInformationalVersion("0.0.0.0")>]
14+
()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
''------------------------------------------------------------------------------
2+
'' <auto-generated>
3+
'' This code was generated by GitVersion.
4+
''
5+
'' You can modify this code as we will not overwrite it when re-executing GitVersion
6+
'' </auto-generated>
7+
''------------------------------------------------------------------------------
8+
9+
Imports System.Reflection
10+
11+
<assembly: AssemblyFileVersion("0.0.0.0")>
12+
<assembly: AssemblyVersion("0.0.0.0")>
13+
<assembly: AssemblyInformationalVersion("0.0.0.0")>

src/GitVersionExe.Tests/ArgumentParserTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,27 @@ public void update_assembly_info_with_relative_filename()
205205
arguments.UpdateAssemblyInfoFileName.ShouldBe("..\\..\\CommonAssemblyInfo.cs");
206206
}
207207

208+
[Test]
209+
public void ensure_assembly_info_true_when_found()
210+
{
211+
var arguments = ArgumentParser.ParseArguments("-ensureAssemblyInfo");
212+
arguments.EnsureAssemblyInfo.ShouldBe(true);
213+
}
214+
215+
[Test]
216+
public void ensure_assembly_info_true()
217+
{
218+
var arguments = ArgumentParser.ParseArguments("-ensureAssemblyInfo true");
219+
arguments.EnsureAssemblyInfo.ShouldBe(true);
220+
}
221+
222+
[Test]
223+
public void ensure_assembly_info_false()
224+
{
225+
var arguments = ArgumentParser.ParseArguments("-ensureAssemblyInfo false");
226+
arguments.EnsureAssemblyInfo.ShouldBe(false);
227+
}
228+
208229
[Test]
209230
public void dynamicRepoLocation()
210231
{

0 commit comments

Comments
 (0)