Skip to content
Closed
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
7 changes: 6 additions & 1 deletion src/Tasks/Microsoft.NET.Build.Tasks/GenerateBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override void ExecuteCore()
foreach (var item in FilesToBundle)
{
fileSpec.Add(new FileSpec(sourcePath: item.ItemSpec,
bundleRelativePath:item.GetMetadata(MetadataKeys.RelativePath)));
bundleRelativePath: NormalizePathDirectorySeparator(item.GetMetadata(MetadataKeys.RelativePath))));
}

bundler.GenerateBundle(fileSpec);
Expand All @@ -64,5 +64,10 @@ protected override void ExecuteCore()

ExcludedFiles = FilesToBundle.Zip(fileSpec, (item, spec) => (spec.Excluded) ? item : null).Where(x => x != null).ToArray();
}

private static string NormalizePathDirectorySeparator(string path)
{
return path.Replace('\\', '/');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<!-- Copy satellite assemblies. -->
<ResolvedFileToPublish Include="@(IntermediateSatelliteAssembliesWithTargetPath)">
<RelativePath>%(IntermediateSatelliteAssembliesWithTargetPath.Culture)\%(Filename)%(Extension)</RelativePath>
<RelativePath>%(IntermediateSatelliteAssembliesWithTargetPath.Culture)/%(Filename)%(Extension)</RelativePath>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work on windows? It seemed like the bundler was treating this as a string, causing \ to be part of a filename on unix, so I naiively would have expected this to just move the problem to windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK / is a reserved character in Windows and cannot be used for naming filenames/folders. This wouldn't be the only place where we use slashes for dir separators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't any other custom Target use backslash, and then it would be broken as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</ResolvedFileToPublish>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,5 +461,113 @@ public void It_runs_single_file_apps(string targetFramework, bool selfContained,
.And
.HaveStdOutContaining("Hello World");
}

[RequiresMSBuildVersionTheory("16.8.0")]
[InlineData("netcoreapp3.0")]
[InlineData("netcoreapp3.1")]
[InlineData("net5.0")]
public void It_runs_single_file_apps_with_satellite_assemblies(string targetFramework)
{
var testProject = new TestProject()
{
Name = "SingleFileTest",
TargetFrameworks = targetFramework,
IsSdkProject = true,
IsExe = true,
SourceFiles =
{
["Program.cs"] = @"
using System;

public static class Program
{
public static void Main()
{
Console.WriteLine(Strings.GetHelloWorld());
}
}",
["Strings.cs"] = @"using System;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Threading;

public class Strings
{
public static string GetHelloWorld()
{
CultureInfo.CurrentUICulture = new CultureInfo(""en-US"");
var resources = new ResourceManager(""Strings"", typeof(Strings).GetTypeInfo().Assembly);
return resources.GetString(""HelloWorld"");
}
}"
},
EmbeddedResources =
{
["Strings.en-US.resx"] = @"<?xml version=""1.0"" encoding=""utf-8""?>
<root>
<xsd:schema id=""root"" xmlns="""" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">
<xsd:element name=""root"" msdata:IsDataSet=""true"">
<xsd:complexType>
<xsd:choice maxOccurs=""unbounded"">
<xsd:element name=""data"">
<xsd:complexType>
<xsd:sequence>
<xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
<xsd:element name=""comment"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""2"" />
</xsd:sequence>
<xsd:attribute name=""name"" type=""xsd:string"" msdata:Ordinal=""1"" />
<xsd:attribute name=""type"" type=""xsd:string"" msdata:Ordinal=""3"" />
<xsd:attribute name=""mimetype"" type=""xsd:string"" msdata:Ordinal=""4"" />
</xsd:complexType>
</xsd:element>
<xsd:element name=""resheader"">
<xsd:complexType>
<xsd:sequence>
<xsd:element name=""value"" type=""xsd:string"" minOccurs=""0"" msdata:Ordinal=""1"" />
</xsd:sequence>
<xsd:attribute name=""name"" type=""xsd:string"" use=""required"" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name=""resmimetype"">
<value>text/microsoft-resx</value>
</resheader>
<resheader name=""version"">
<value>1.3</value>
</resheader>
<resheader name=""reader"">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name=""writer"">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name=""HelloWorld"" xml:space=""preserve"">
<value>Hello World!</value>
</data>
</root>"
}
};

var testAsset = _testAssetsManager.CreateTestProject(testProject);
var publishCommand = new PublishCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name));

publishCommand.Execute(PublishSingleFile, RuntimeIdentifier)
.Should()
.Pass();

var publishDir = GetPublishDirectory(publishCommand, targetFramework).FullName;
var singleFilePath = Path.Combine(publishDir, $"{testProject.Name}{Constants.ExeSuffix}");

var command = new RunExeCommand(Log, singleFilePath);
command.Execute()
.Should()
.Pass()
.And
.HaveStdOutContaining("Hello World!");
}
}
}