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

Set default SlnGenProjectName for Traversal projects #559

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion src/Traversal.UnitTests/TraversalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,12 @@ public void PropertiesAreSet(string target)
[InlineData("TraversalProjectNames", "custom.proj", "custom.proj")]
[InlineData("TraversalProjectNames", null, "dirs.proj")]
[InlineData("UsingMicrosoftTraversalSdk", null, "true")]
[InlineData("SlnGenProjectName", null, "ProjectA")]
[InlineData("SlnGenProjectName", "custom", "custom")]
public void PropertiesHaveExpectedValues(string propertyName, string value, string expectedValue)
{
ProjectCreator.Templates.TraversalProject(
path: GetTempFile("dirs.proj"))
path: Path.Combine(TestRootPath, "ProjectA", "dirs.proj"))
.Property(propertyName, value)
.Save()
.TryGetPropertyValue(propertyName, out string actualValue);
Expand Down
11 changes: 11 additions & 0 deletions src/Traversal/Sdk/Traversal.targets
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
<TargetFramework Condition="'$(TargetFramework)' == ''">net45</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<!--
If the project hasn't customized its name, use the name of the parent folder. This avoids every IDE window being named "dirs".

We check the property twice to handle the unlikely situation where the project is at the root of a drive, and thus
the folder would otherwise be ''.
-->
<SlnGenProjectName Condition="'$(SlnGenProjectName)' == ''">$([System.IO.Path]::GetFileName($([System.IO.Path]::GetDirectoryName($(MSBuildProjectFullPath)))))</SlnGenProjectName>
<SlnGenProjectName Condition="'$(SlnGenProjectName)' == ''">$(MSBuildProjectName)</SlnGenProjectName>
</PropertyGroup>

<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<ItemGroup>
Expand Down