Skip to content

Commit

Permalink
Allow project properties to specify custom comment
Browse files Browse the repository at this point in the history
This can help workaround the issue of the value having invalid content for an XML summary element (i..e. the value has XML).

Further fixes #390
  • Loading branch information
kzu committed Oct 8, 2024
1 parent 6ea45bd commit 8dd8763
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ThisAssembly.Project/ThisAssembly.Project.targets
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</ItemGroup>
<ItemGroup>
<!-- Collect requested properties, and eval their value -->
<Constant Include="@(ProjectPropertyDistinct -> 'Project.%(Identity)')" Value="$(%(ProjectPropertyDistinct.Identity))" Root="." />
<Constant Include="@(ProjectPropertyDistinct -> 'Project.%(Identity)')" Value="$(%(ProjectPropertyDistinct.Identity))" Comment="%(ProjectPropertyDistinct.Comment)" Root="." />
</ItemGroup>
</Target>

Expand Down
2 changes: 1 addition & 1 deletion src/ThisAssembly.Project/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ them as `ProjectProperty` MSBuild items in the project file, such as:
</PropertyGroup>
<ItemGroup>
<!-- Opt-in to emitting that property value as a constant in ThisAssembly.Project -->
<ProjectProperty Include="Foo" />
<ProjectProperty Include="Foo" Comment="This comment replaces the default comment :)" />
</ItemGroup>
```

Expand Down
7 changes: 7 additions & 0 deletions src/ThisAssembly.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ with a newline and
// Some comments too.
""".ReplaceLineEndings(), ThisAssembly.Project.Multiline.ReplaceLineEndings());

[Fact]
public void CanUseProjectFullFileContents()
{
Assert.NotEmpty(ThisAssembly.Project.ProjectFile);
Assert.False(ThisAssembly.Project.ProjectFile.StartsWith("|"));
}

[Fact]
public void CanUseConstants()
=> Assert.Equal("Baz", ThisAssembly.Constants.Foo.Bar);
Expand Down
2 changes: 2 additions & 0 deletions src/ThisAssembly.Tests/ThisAssembly.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<!--<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>-->
<NoWarn>CS0618;CS8981;TA100;$(NoWarn)</NoWarn>
<PackageScribanIncludeSource>false</PackageScribanIncludeSource>
<ProjectFile>$([System.IO.File]::ReadAllText($(MSBuildProjectFullPath)))</ProjectFile>
</PropertyGroup>

<Import Project="..\*\ThisAssembly*.props" />
Expand Down Expand Up @@ -66,6 +67,7 @@
<ProjectProperty Include="Foo" />
<ProjectProperty Include="Description" />
<ProjectProperty Include="Multiline" />
<ProjectProperty Include="ProjectFile" Comment="Full project contents" />
<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 😍" />
Expand Down

0 comments on commit 8dd8763

Please sign in to comment.