Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify IsDirty with newer typed constants in ThisAssembly #368

Merged
merged 1 commit into from
Oct 29, 2024
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
14 changes: 0 additions & 14 deletions GitInfo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A5ED9F27-FAE0-45B7-84F9-9D6C35C7E1AC}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.github\workflows\build.yml = .github\workflows\build.yml
src\Directory.props = src\Directory.props
.github\workflows\publish.yml = .github\workflows\publish.yml
EndProjectSection
EndProject
Project("{13B669BE-BB05-4DDF-9536-439F39A36129}") = "GitInfo", "src\GitInfo\GitInfo.msbuildproj", "{1D5D9080-CF62-49E1-87AC-F2EDA58A824E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeAnalysis", "src\Analyzer\CodeAnalysis.csproj", "{B96EB399-A569-4C4B-A702-99D6050B1FAF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -25,10 +15,6 @@ Global
{1D5D9080-CF62-49E1-87AC-F2EDA58A824E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D5D9080-CF62-49E1-87AC-F2EDA58A824E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D5D9080-CF62-49E1-87AC-F2EDA58A824E}.Release|Any CPU.Build.0 = Release|Any CPU
{B96EB399-A569-4C4B-A702-99D6050B1FAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B96EB399-A569-4C4B-A702-99D6050B1FAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B96EB399-A569-4C4B-A702-99D6050B1FAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B96EB399-A569-4C4B-A702-99D6050B1FAF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
33 changes: 33 additions & 0 deletions src/Directory.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project InitialTargets="SetLocalVersion">

<Target Name="SetLocalVersion" Condition="!$(CI)">
<GetVersion>
<Output TaskParameter="Version" PropertyName="Version" />
</GetVersion>
</Target>

<UsingTask TaskName="GetVersion" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Version Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="Microsoft.Build.Framework"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
var version = this.BuildEngine4.GetRegisteredTaskObject("Version", RegisteredTaskObjectLifetime.Build);
if (version == null)
{
var epoc = DateTime.Parse("2024-03-15");
var days = Math.Truncate(DateTime.UtcNow.Subtract(epoc).TotalDays);
var time = Math.Floor(DateTime.UtcNow.TimeOfDay.TotalMinutes);
version = "42." + days + "." + time;
this.BuildEngine4.RegisterTaskObject("Version", version, RegisteredTaskObjectLifetime.Build, false);
}
Version = (string)version;
]]>
</Code>
</Task>
</UsingTask>

</Project>
9 changes: 3 additions & 6 deletions src/GitInfo/GitInfo.msbuildproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
<PackageReadmeFile>readme.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGetizer" Version="1.0.4" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Constants" Version="1.4.1" Pack="true" TargetFramework="netstandard2.0" />
<PackageReference Include="NuGetizer" Version="1.2.3" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="ThisAssembly.Constants" Version="2.0.5" Pack="true" TargetFramework="netstandard2.0" />
</ItemGroup>
<ItemGroup>
<None Include="build/**/*.*" />
<None Include="buildMultiTargeting/**/*.*" />
<None Include="buildTransitive/**/*.*" />
<None Include="..\..\readme.md" PackagePath="readme.md" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Analyzer\CodeAnalysis.csproj" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/GitInfo/build/GitInfo.ThisAssembly.targets
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<Constant Include="IsDirtyString" Value="true" Root="Git" Condition="$(GitIsDirty) == '1'" />
<Constant Include="IsDirtyString" Value="false" Root="Git" Condition="$(GitIsDirty) == '0'" />

<Constant Include="IsDirty" Value="true" Root="Git" Condition="$(GitIsDirty) == '1'" Type="bool" />
<Constant Include="IsDirty" Value="false" Root="Git" Condition="$(GitIsDirty) == '0'" Type="bool" />

<Constant Include="RepositoryUrl" Value="$(GitRepositoryUrl)" Root="Git" />

<Constant Include="Branch" Value="$(GitBranch)" Root="Git" />
Expand Down
6 changes: 3 additions & 3 deletions src/GitInfo/build/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -953,10 +953,10 @@

<Import Project="GitInfo.AssemblyMetadata.targets" Condition="'$(GitThisAssemblyMetadata)' == 'true'" />

<!-- Legacy generation in place for non-C# or when the unsupported ThisAssemblyNamespace is in use -->
<Import Project="GitInfo.AssemblyInfo.targets" Condition="'$(Language)' != 'C#' or '$(ThisAssemblyNamespace)' != '' or '$(UseTemplatedCode)' == 'true'" />
<!-- Legacy generation in place for non-C# or when opted in to templates -->
<Import Project="GitInfo.AssemblyInfo.targets" Condition="'$(Language)' != 'C#' or '$(UseTemplatedCode)' == 'true'" />
<!-- Otherwise, for C# we always use ThisAssembly instead. -->
<Import Project="GitInfo.ThisAssembly.targets" Condition="'$(Language)' == 'C#' and '$(ThisAssemblyNamespace)' == '' and '$(UseTemplatedCode)' != 'true'" />
<Import Project="GitInfo.ThisAssembly.targets" Condition="'$(Language)' == 'C#' and '$(UseTemplatedCode)' != 'true'" />

<PropertyGroup>
<GitInfoImported>true</GitInfoImported>
Expand Down