Repository navigation
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
77 lines (69 loc) Β· 3.04 KB
/
Copy pathDirectory.Build.targets
File metadata and controls
77 lines (69 loc) Β· 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<Project>
<!--
Compose IgFullVersion and generate AppBuildInfo.g.cs for executable projects.
The version is baked in as a const string. Fully AOT-safe, no reflection needed.
-->
<!-- Compose IgFullVersion, Version, FileVersion for executable projects -->
<PropertyGroup Condition="'$(OutputType)' == 'WinExe' OR '$(OutputType)' == 'Exe'">
<IgFullVersion Condition="'$(IgReleaseType)' != ''">$(IgVersion)-$(IgReleaseType)-$(IgPlatformId)-$(Platform)</IgFullVersion>
<IgFullVersion Condition="'$(IgReleaseType)' == ''">$(IgVersion)-$(IgPlatformId)-$(Platform)</IgFullVersion>
<Version>$(IgFullVersion)</Version>
<FileVersion>$(IgVersion)</FileVersion>
</PropertyGroup>
<!-- Inline task: writes the C# source file without XML-escaped code -->
<UsingTask TaskName="_GenerateVersionFile"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<OutputPath ParameterType="System.String" Required="true" />
<Namespace ParameterType="System.String" Required="true" />
<Version ParameterType="System.String" Required="true" />
<FullVersion ParameterType="System.String" Required="true" />
<ReleaseType ParameterType="System.String" Required="false" />
<UpdateChannel ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
var code = $$"""
// <auto-generated/>
using ImageGlass.Common.Types;
namespace ImageGlass.Common;
internal class AppBuildInfo : IAppBuildInfo
{
public string Version { get; } = "{{Version}}";
public string FullVersion { get; } = "{{FullVersion}}";
public string ReleaseType { get; } = "{{ReleaseType}}";
public string UpdateChannel { get; } = "{{UpdateChannel}}";
}
""";
var dir = System.IO.Path.GetDirectoryName(OutputPath);
if (!string.IsNullOrEmpty(dir))
System.IO.Directory.CreateDirectory(dir);
// Only write when content changed to avoid unnecessary rebuilds
if (!System.IO.File.Exists(OutputPath) || System.IO.File.ReadAllText(OutputPath) != code)
System.IO.File.WriteAllText(OutputPath, code);
]]></Code>
</Task>
</UsingTask>
<!-- Generate AppBuildInfo.g.cs -->
<Target Name="GenerateAppBuildInfo"
BeforeTargets="CoreCompile"
DependsOnTargets="PrepareForBuild"
Condition="('$(OutputType)' == 'WinExe' OR '$(OutputType)' == 'Exe') AND '$(GenerateIgAppBuildInfo)' != 'false'">
<PropertyGroup>
<_AppBuildInfoFile>$(IntermediateOutputPath)AppBuildInfo.g.cs</_AppBuildInfoFile>
</PropertyGroup>
<_GenerateVersionFile
OutputPath="$(_AppBuildInfoFile)"
Namespace="$(RootNamespace)"
Version="$(IgVersion)"
FullVersion="$(IgFullVersion)"
ReleaseType="$(IgReleaseType)"
UpdateChannel="$(IgUpdateChannel)" />
<ItemGroup>
<Compile Remove="$(_AppBuildInfoFile)" />
<Compile Include="$(_AppBuildInfoFile)" />
</ItemGroup>
</Target>
</Project>