Skip to content

Commit 12ac970

Browse files
committed
Adds support for SQL project files
Adds support for updating SQL project files (.sqlproj) This allows GitVersion to update AssemblyInfo files in SQL projects.
1 parent 724e5d5 commit 12ac970

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

docs/input/docs/usage/cli/arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ GitVersion [path]
6666
the git repo and update them
6767
/updateprojectfiles
6868
Will recursively search for all project files
69-
(.csproj/.vbproj/.fsproj) files in the git repo and update
69+
(.csproj/.vbproj/.fsproj/.sqlproj) files in the git repo and update
7070
them
7171
Note: This is only compatible with the newer Sdk projects
7272
/ensureassemblyinfo

src/GitVersion.Output.Tests/Output/ProjectFileUpdaterTests.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public void Setup()
4545
[TestCase("Microsoft.NET.Sdk.WindowsDesktop")]
4646
[TestCase("Microsoft.NET.Sdk.Razor")]
4747
[TestCase("Microsoft.NET.Sdk.BlazorWebAssembly")]
48+
[TestCase("Microsoft.Build.Sql")]
4849
public void CanUpdateProjectFileWithSdkProjectFileXml(string sdk)
4950
{
5051
var xml = $"""
@@ -77,7 +78,7 @@ public void CannotUpdateProjectFileWithIncorrectProjectSdk(string xml)
7778

7879
logMessages.ShouldNotBeEmpty();
7980
logMessages.Count.ShouldBe(1);
80-
logMessages[0].ShouldContain("Specified project file Sdk (SomeOtherProject.Sdk) is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk'");
81+
logMessages[0].ShouldContain("Specified project file Sdk (SomeOtherProject.Sdk) is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk' or 'Microsoft.Build.Sql'");
8182
}
8283

8384
[TestCase($"""
@@ -96,7 +97,7 @@ public void CannotUpdateProjectFileWithMissingProjectSdk(string xml)
9697

9798
logMessages.ShouldNotBeEmpty();
9899
logMessages.Count.ShouldBe(1);
99-
logMessages[0].ShouldContain("Specified project file Sdk () is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk'");
100+
logMessages[0].ShouldContain("Specified project file Sdk () is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk' or 'Microsoft.Build.Sql'");
100101
}
101102

102103
[TestCase($"""
@@ -263,37 +264,36 @@ public void UpdateProjectXmlVersionElementWithMultipleVersionElementsLastOneIsMo
263264
xmlRoot.ToString().ShouldBe(expectedXml.ToString());
264265
}
265266

266-
[TestCase("""
267-
268-
<Project Sdk="Microsoft.NET.Sdk">
269-
<PropertyGroup>
270-
<OutputType>Exe</OutputType>
271-
<TargetFramework>net8.0</TargetFramework>
272-
</PropertyGroup>
273-
</Project>
274-
""")]
275-
public void UpdateProjectFileAddsVersionToFile(string xml)
267+
[TestCase("Microsoft.NET.Sdk", "TestProject.csproj")]
268+
[TestCase("Microsoft.Build.Sql", "TestProject.sqlproj")]
269+
public void UpdateProjectFileAddsVersionToFile(string sdk, string projectName)
276270
{
271+
var xml = $"""
272+
<Project Sdk="{sdk}">
273+
<PropertyGroup>
274+
<TargetFramework>net8.0</TargetFramework>
275+
</PropertyGroup>
276+
</Project>
277+
""";
277278
var workingDirectory = FileSystemHelper.Path.GetTempPath();
278-
var fileName = FileSystemHelper.Path.Combine(workingDirectory, "TestProject.csproj");
279+
var fileName = FileSystemHelper.Path.Combine(workingDirectory, projectName);
279280

280281
VerifyAssemblyInfoFile(xml, fileName, AssemblyVersioningScheme.MajorMinorPatch, (fs, variables) =>
281282
{
282283
using var projFileUpdater = new ProjectFileUpdater(this.log, fs);
283284
projFileUpdater.Execute(variables, new(workingDirectory, false, fileName));
284285

285-
const string expectedXml = $"""
286-
<Project Sdk="Microsoft.NET.Sdk">
287-
<PropertyGroup>
288-
<OutputType>Exe</OutputType>
289-
<TargetFramework>{TargetFramework}</TargetFramework>
290-
<AssemblyVersion>2.3.1.0</AssemblyVersion>
291-
<FileVersion>2.3.1.0</FileVersion>
292-
<InformationalVersion>2.3.1+3.Branch.foo.Sha.hash</InformationalVersion>
293-
<Version>2.3.1</Version>
294-
</PropertyGroup>
295-
</Project>
296-
""";
286+
var expectedXml = $"""
287+
<Project Sdk="{sdk}">
288+
<PropertyGroup>
289+
<TargetFramework>{TargetFramework}</TargetFramework>
290+
<AssemblyVersion>2.3.1.0</AssemblyVersion>
291+
<FileVersion>2.3.1.0</FileVersion>
292+
<InformationalVersion>2.3.1+3.Branch.foo.Sha.hash</InformationalVersion>
293+
<Version>2.3.1</Version>
294+
</PropertyGroup>
295+
</Project>
296+
""";
297297
var transformedXml = fs.File.ReadAllText(fileName);
298298
transformedXml.ShouldBe(XElement.Parse(expectedXml).ToString());
299299
});

src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ public bool CanUpdateProjectFile(XElement xmlRoot)
110110
}
111111

112112
var sdkAttribute = xmlRoot.Attribute("Sdk");
113-
if (sdkAttribute?.Value.StartsWith("Microsoft.NET.Sdk") != true)
113+
if (sdkAttribute?.Value.StartsWith("Microsoft.NET.Sdk") != true &&
114+
sdkAttribute?.Value.StartsWith("Microsoft.Build.Sql") != true)
114115
{
115-
log.Warning($"Specified project file Sdk ({sdkAttribute?.Value}) is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk'");
116+
log.Warning($"Specified project file Sdk ({sdkAttribute?.Value}) is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk' or 'Microsoft.Build.Sql'");
116117
return false;
117118
}
118119

@@ -217,6 +218,7 @@ private static bool IsSupportedProjectFile(string fileName)
217218

218219
return fileName.EndsWith(".csproj") ||
219220
fileName.EndsWith(".fsproj") ||
220-
fileName.EndsWith(".vbproj");
221+
fileName.EndsWith(".vbproj") ||
222+
fileName.EndsWith(".sqlproj");
221223
}
222224
}

0 commit comments

Comments
 (0)