Class MsBuildUtil
- Namespace
- Invex.Atom.Module.Dotnet.Util
- Assembly
- Invex.Atom.Module.Dotnet.dll
Provides utility methods for working with MSBuild project files, specifically for managing version information.
public static class MsBuildUtil
- Inheritance
-
objectMsBuildUtil
Remarks
This utility class offers functionality to manipulate MSBuild project files by updating version-related properties. It ensures consistent version management across different version properties in MSBuild projects.
Methods
SetVersionInfo(string, SemVer)
Updates an MSBuild project file XML with version information from a semantic version.
public static string SetVersionInfo(string file, SemVer version)
Parameters
filestringThe MSBuild project file content as an XML string.
versionSemVerThe semantic version to apply to the project file.
Returns
- string
The updated MSBuild project file content as an XML string with version properties set.
Examples
var projectXml = File.ReadAllText("MyProject.csproj");
var version = SemVer.Parse("1.2.3-beta.4");
var updatedXml = MsBuildUtil.SetVersionInfo(projectXml, version);
File.WriteAllText("MyProject.csproj", updatedXml);
Remarks
This method performs the following operations:
- Removes all existing version-related properties from PropertyGroup elements
- Creates a new PropertyGroup with standardized version properties
- Sets Version to the semantic version prefix
- Sets PackageVersion to the full semantic version
- Sets AssemblyVersion to the prefix with ".0" appended
- Sets FileVersion to the prefix with build number from pre-release
- Sets InformationalVersion to the full semantic version
The method removes duplicate version properties to ensure clean project files and consistent versioning.
Exceptions
- XmlException
Thrown when the input file content is not valid XML.