Skip to content

Commit a767756

Browse files
Copilotarturcic
andcommitted
Add support for SQL SDK .sqlproj files
Co-authored-by: arturcic <[email protected]>
1 parent fcef7b5 commit a767756

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

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

Lines changed: 37 additions & 2 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($"""
@@ -299,6 +300,40 @@ public void UpdateProjectFileAddsVersionToFile(string xml)
299300
});
300301
}
301302

303+
[TestCase("""
304+
305+
<Project Sdk="Microsoft.Build.Sql">
306+
<PropertyGroup>
307+
<TargetFramework>net8.0</TargetFramework>
308+
</PropertyGroup>
309+
</Project>
310+
""")]
311+
public void UpdateSqlProjectFileAddsVersionToFile(string xml)
312+
{
313+
var workingDirectory = FileSystemHelper.Path.GetTempPath();
314+
var fileName = FileSystemHelper.Path.Combine(workingDirectory, "TestProject.sqlproj");
315+
316+
VerifyAssemblyInfoFile(xml, fileName, AssemblyVersioningScheme.MajorMinorPatch, (fs, variables) =>
317+
{
318+
using var projFileUpdater = new ProjectFileUpdater(this.log, fs);
319+
projFileUpdater.Execute(variables, new(workingDirectory, false, fileName));
320+
321+
const string expectedXml = $"""
322+
<Project Sdk="Microsoft.Build.Sql">
323+
<PropertyGroup>
324+
<TargetFramework>{TargetFramework}</TargetFramework>
325+
<AssemblyVersion>2.3.1.0</AssemblyVersion>
326+
<FileVersion>2.3.1.0</FileVersion>
327+
<InformationalVersion>2.3.1+3.Branch.foo.Sha.hash</InformationalVersion>
328+
<Version>2.3.1</Version>
329+
</PropertyGroup>
330+
</Project>
331+
""";
332+
var transformedXml = fs.File.ReadAllText(fileName);
333+
transformedXml.ShouldBe(XElement.Parse(expectedXml).ToString());
334+
});
335+
}
336+
302337
private void VerifyAssemblyInfoFile(
303338
string projectFileContent,
304339
string fileName,

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)