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
5 changes: 5 additions & 0 deletions src/ThisAssembly.Constants/ConstantsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
x.Right.GetOptions(x.Left).TryGetValue("build_metadata.Constant.Value", out var value);
x.Right.GetOptions(x.Left).TryGetValue("build_metadata.Constant.Comment", out var comment);
x.Right.GetOptions(x.Left).TryGetValue("build_metadata.Constant.Root", out var root);

// Revert auto-escaping due to https://github.com/dotnet/roslyn/issues/51692
if (value != null && value.StartsWith("|") && value.EndsWith("|"))
value = value[1..^1].Replace('|', ';');

return (
name: Path.GetFileName(x.Left.Path),
value: value!,
Expand Down
7 changes: 6 additions & 1 deletion src/ThisAssembly.Constants/ThisAssembly.Constants.targets
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun"
DependsOnTargets="PrepareResourceNames;PrepareConstants">
<ItemGroup>
<AdditionalFiles Include="@(Constant)" SourceItemType="Constant" />
<!-- Automatically handle escaping of ; due to https://github.com/dotnet/roslyn/issues/51692 -->
<Constant Update="@(Constant)" Condition="$([MSBuild]::ValueOrdefault('%(Constant.Value)', '').Contains(';'))">
<Value>|$([MSBuild]::ValueOrdefault('%(Constant.Value)', '').Replace(';', '|'))|</Value>
</Constant>

<AdditionalFiles Include="@(Constant)" SourceItemType="Constant" />
</ItemGroup>
</Target>

Expand Down
4 changes: 4 additions & 0 deletions src/ThisAssembly.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,8 @@ public void CanUseGitBranchConstants()
Assert.NotEmpty(ThisAssembly.Git.Branch);
Output.WriteLine(ThisAssembly.Git.Branch);
}

[Fact]
public void CanUseSemicolonsInConstant()
=> Assert.Equal("A;B;C", ThisAssembly.Constants.WithSemiColon);
}
1 change: 1 addition & 0 deletions src/ThisAssembly.Tests/ThisAssembly.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Constant Include="Foo.Raw" Value="$(Multiline)" Comment="$(Multiline)" />
<Constant Include="Foo.Bar" Value="Baz" Comment="Yay!" />
<Constant Include="Foo.Hello" Value="World" Comment="Comments make everything better 😍" />
<Constant Include="WithSemiColon" Value="A;B;C" />
<FileConstant Include="@(None)" />
<FileConstant Update="@(FileConstant -&gt; WithMetadataValue('Filename', 'Readme'))">
<Link>Included/%(Filename)%(Extension)</Link>
Expand Down