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
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<TargetPath Condition="'%(Content.TargetPath)' != ''">%(Content.TargetPath)</TargetPath>
<TargetPath Condition="'%(Content.TargetPath)' == '' and '%(Content.Link)' != ''">%(Content.Link)</TargetPath>
<!-- Use MSBuildProjectDirectory as the base for relative path computation. DefiningProjectDirectory can point to sdk targets folder and lead to unexpected paths. -->
<TargetPath Condition="'%(Content.TargetPath)' == '' and '%(Content.Link)' == ''">$([MSBuild]::MakeRelative($(MSBuildProjectDirectory), %(Content.FullPath)))</TargetPath>
<TargetPath Condition="'%(Content.TargetPath)' == '' and '%(Content.Link)' == ''">$([MSBuild]::MakeRelative('$(MSBuildProjectDirectory)', '%(Content.FullPath)'))</TargetPath>
</_ContentWithPublishMetadata>

<ContentWithTargetPath Include="@(_ContentWithPublishMetadata)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,49 @@ public void It_publishes_content_from_imported_targets_with_correct_path()
.Where(f => !f.StartsWith(publishDirectory.FullName));
potentialEscapedFiles.Should().BeEmpty("Content file should not escape to directories outside publish folder");
}

[Fact]
public void It_publishes_content_with_comma_in_filename()
{
// This test verifies that Content items with commas in their filenames can be published
// without triggering MSB4186 due to the comma being interpreted as an argument separator
// in the [MSBuild]::MakeRelative property function call.

var testProject = new TestProject()
{
Name = "PublishCommaContent",
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
IsExe = true
};

testProject.SourceFiles["Program.cs"] = "class Program { static void Main() { } }";

var testAsset = _testAssetsManager.CreateTestProject(testProject);

var projectDirectory = Path.Combine(testAsset.Path, testProject.Name);

// Create a content file with a comma in the filename (e.g., a variable font file)
var contentFileName = "Doto-VariableFont_ROND,wght.ttf";
var contentFile = Path.Combine(projectDirectory, contentFileName);
File.WriteAllText(contentFile, "fake font content");

// Update the project file to include the content file with CopyToPublishDirectory
var projectFile = Path.Combine(projectDirectory, $"{testProject.Name}.csproj");
var projectContent = File.ReadAllText(projectFile);
projectContent = projectContent.Replace("</Project>", @"
<ItemGroup>
<Content Include=""Doto-VariableFont_ROND,wght.ttf"" CopyToPublishDirectory=""IfDifferent"" />
</ItemGroup>
</Project>");
File.WriteAllText(projectFile, projectContent);

var publishCommand = new PublishCommand(testAsset);
var publishResult = publishCommand.Execute();

publishResult.Should().Pass();

var publishDirectory = publishCommand.GetOutputDirectory(testProject.TargetFrameworks);
publishDirectory.Should().HaveFile(contentFileName);
}
}
}
Loading