Skip to content
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
2 changes: 1 addition & 1 deletion docs/input/docs/usage/cli/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ GitVersion [path]
the git repo and update them
/updateprojectfiles
Will recursively search for all project files
(.csproj/.vbproj/.fsproj) files in the git repo and update
(.csproj/.vbproj/.fsproj/.sqlproj) files in the git repo and update
them
Note: This is only compatible with the newer Sdk projects
/ensureassemblyinfo
Expand Down
50 changes: 25 additions & 25 deletions src/GitVersion.Output.Tests/Output/ProjectFileUpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void Setup()
[TestCase("Microsoft.NET.Sdk.WindowsDesktop")]
[TestCase("Microsoft.NET.Sdk.Razor")]
[TestCase("Microsoft.NET.Sdk.BlazorWebAssembly")]
[TestCase("Microsoft.Build.Sql")]
public void CanUpdateProjectFileWithSdkProjectFileXml(string sdk)
{
var xml = $"""
Expand Down Expand Up @@ -77,7 +78,7 @@ public void CannotUpdateProjectFileWithIncorrectProjectSdk(string xml)

logMessages.ShouldNotBeEmpty();
logMessages.Count.ShouldBe(1);
logMessages[0].ShouldContain("Specified project file Sdk (SomeOtherProject.Sdk) is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk'");
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'");
}

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

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

[TestCase($"""
Expand Down Expand Up @@ -263,37 +264,36 @@ public void UpdateProjectXmlVersionElementWithMultipleVersionElementsLastOneIsMo
xmlRoot.ToString().ShouldBe(expectedXml.ToString());
}

[TestCase("""

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
""")]
public void UpdateProjectFileAddsVersionToFile(string xml)
[TestCase("Microsoft.NET.Sdk", "TestProject.csproj")]
[TestCase("Microsoft.Build.Sql", "TestProject.sqlproj")]
public void UpdateProjectFileAddsVersionToFile(string sdk, string projectName)
{
var xml = $"""
<Project Sdk="{sdk}">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
""";
var workingDirectory = FileSystemHelper.Path.GetTempPath();
var fileName = FileSystemHelper.Path.Combine(workingDirectory, "TestProject.csproj");
var fileName = FileSystemHelper.Path.Combine(workingDirectory, projectName);

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

const string expectedXml = $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>{TargetFramework}</TargetFramework>
<AssemblyVersion>2.3.1.0</AssemblyVersion>
<FileVersion>2.3.1.0</FileVersion>
<InformationalVersion>2.3.1+3.Branch.foo.Sha.hash</InformationalVersion>
<Version>2.3.1</Version>
</PropertyGroup>
</Project>
""";
var expectedXml = $"""
<Project Sdk="{sdk}">
<PropertyGroup>
<TargetFramework>{TargetFramework}</TargetFramework>
<AssemblyVersion>2.3.1.0</AssemblyVersion>
<FileVersion>2.3.1.0</FileVersion>
<InformationalVersion>2.3.1+3.Branch.foo.Sha.hash</InformationalVersion>
<Version>2.3.1</Version>
</PropertyGroup>
</Project>
""";
var transformedXml = fs.File.ReadAllText(fileName);
transformedXml.ShouldBe(XElement.Parse(expectedXml).ToString());
});
Expand Down
8 changes: 5 additions & 3 deletions src/GitVersion.Output/AssemblyInfo/ProjectFileUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ public bool CanUpdateProjectFile(XElement xmlRoot)
}

var sdkAttribute = xmlRoot.Attribute("Sdk");
if (sdkAttribute?.Value.StartsWith("Microsoft.NET.Sdk") != true)
if (sdkAttribute?.Value.StartsWith("Microsoft.NET.Sdk") != true &&
sdkAttribute?.Value.StartsWith("Microsoft.Build.Sql") != true)
{
log.Warning($"Specified project file Sdk ({sdkAttribute?.Value}) is not supported, please ensure the project sdk starts with 'Microsoft.NET.Sdk'");
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'");
return false;
}

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

return fileName.EndsWith(".csproj") ||
fileName.EndsWith(".fsproj") ||
fileName.EndsWith(".vbproj");
fileName.EndsWith(".vbproj") ||
fileName.EndsWith(".sqlproj");
}
}
Loading