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
9 changes: 9 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,15 @@ them as `ProjectProperty` MSBuild items in the project file, such as:
</ItemGroup>
```

The same opt-in can be the `ProjectProperty` MSBuild property instead of items. Its value is
included as-is as `@(ProjectProperty)` items, so semicolon-separated names work. This is the
path for [file-based apps](https://learn.microsoft.com/dotnet/core/sdk/file-based-apps):

```csharp
#:package ThisAssembly.Project
#:property ProjectProperty=MSBuildProjectDirectory
```

![](https://raw.githubusercontent.com/devlooped/ThisAssembly/main/img/ThisAssembly.Project.png)

<!-- #project -->
Expand Down
4 changes: 4 additions & 0 deletions src/ThisAssembly.Project/ThisAssembly.Project.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ them as `ProjectProperty` MSBuild items in project file, such as:
&lt;ProjectProperty Include="Foo" /&gt;
&lt;/ItemGroup&gt;

Or via the ProjectProperty MSBuild property (included as-is as items), which file-based apps can set with:

#:property ProjectProperty=MSBuildProjectDirectory

A corresponding `ThisAssembly.Project.Foo` constant with the value `Bar` is provided.

Generated code:
Expand Down
2 changes: 2 additions & 0 deletions src/ThisAssembly.Project/ThisAssembly.Project.targets
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

<Target Name="PrepareProjectProperties" BeforeTargets="PrepareConstants" DependsOnTargets="$(PrepareProjectPropertiesDependsOn)">
<ItemGroup>
<!-- File-based apps can pass #:property ProjectProperty=Name;Other -->
<ProjectProperty Include="$(ProjectProperty)" Condition="'$(ProjectProperty)' != ''" />
<ProjectPropertyDistinct Include="@(ProjectProperty -> Distinct())" />
</ItemGroup>
<ItemGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/ThisAssembly.Project/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ them as `ProjectProperty` MSBuild items in the project file, such as:
</ItemGroup>
```

The same opt-in can be the `ProjectProperty` MSBuild property instead of items. Its value is
included as-is as `@(ProjectProperty)` items, so semicolon-separated names work. This is the
path for [file-based apps](https://learn.microsoft.com/dotnet/core/sdk/file-based-apps):

```csharp
#:package ThisAssembly.Project
#:property ProjectProperty=MSBuildProjectDirectory
```

![](https://raw.githubusercontent.com/devlooped/ThisAssembly/main/img/ThisAssembly.Project.png)

<!-- #project -->
Expand Down
8 changes: 8 additions & 0 deletions src/ThisAssembly.Tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ public void CanUseHierarchicalMetadata()
public void CanUseProjectProperty()
=> Assert.Equal("Bar", ThisAssembly.Project.Foo);

/// <summary />
[Fact]
public void CanUseProjectPropertyFromProperty()
{
Assert.Equal("from-property", ThisAssembly.Project.FromProjectProperty);
Assert.Equal("also-from-property", ThisAssembly.Project.AlsoFromProjectProperty);
}

/// <summary />
[Fact]
public void CanUseProjectProperty2()
Expand Down
3 changes: 3 additions & 0 deletions src/ThisAssembly.Tests/ThisAssembly.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@

<PropertyGroup>
<Foo>Bar</Foo>
<FromProjectProperty>from-property</FromProjectProperty>
<AlsoFromProjectProperty>also-from-property</AlsoFromProjectProperty>
<ProjectProperty>FromProjectProperty;AlsoFromProjectProperty</ProjectProperty>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading