Merge pull request #1434 from dotnet/brthor/1280/resgen-spaces
Fix Resgen with Spaces in Path
This commit is contained in:
commit
23907bc924
9 changed files with 132 additions and 21 deletions
|
@ -28,6 +28,7 @@ namespace Microsoft.DotNet.Cli.Build
|
|||
"dotnet-compile.UnitTests",
|
||||
"dotnet-build.Tests",
|
||||
"dotnet-pack.Tests",
|
||||
"dotnet-resgen.Tests",
|
||||
"Microsoft.DotNet.Cli.Utils.Tests",
|
||||
"Microsoft.DotNet.Compiler.Common.Tests",
|
||||
"Microsoft.Extensions.DependencyModel.Tests",
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
|
||||
# Put the stage2 output on the front of the path
|
||||
$stage2 = "$PSScriptRoot\..\artifacts\win7-x64\stage2\bin"
|
||||
$stage2 = "$PSScriptRoot\..\artifacts\win10-x64\stage2\bin"
|
||||
if (Test-Path $stage2) {
|
||||
$splat = $env:PATH.Split(";")
|
||||
$stage2 = Convert-Path $stage2
|
||||
|
@ -12,5 +12,5 @@ if (Test-Path $stage2) {
|
|||
$env:PATH="$stage2;$env:PATH"
|
||||
}
|
||||
} else {
|
||||
Write-Host "You don't have a dev build in the 'artifacts\win7-x64\stage2' folder!"
|
||||
Write-Host "You don't have a dev build in the 'artifacts\win10-x64\stage2' folder!"
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Csc
|
|||
|
||||
allArgs.AddRange(analyzers.Select(a => $"-a:\"{a.Trim('"')}\""));
|
||||
allArgs.AddRange(references.Select(r => $"-r:\"{r.Trim('"')}\""));
|
||||
allArgs.AddRange(resources.Select(resource => $"-resource:{resource.Trim('"')}"));
|
||||
allArgs.AddRange(resources.Select(resource => $"-resource:{resource}"));
|
||||
allArgs.AddRange(sources.Select(s => $"\"{s.Trim('"')}\""));
|
||||
|
||||
var rsp = Path.Combine(tempOutputStrippedSpaces, "dotnet-compile-csc.rsp");
|
||||
|
|
|
@ -56,8 +56,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
{
|
||||
var arguments = new[]
|
||||
{
|
||||
resgenFile.InputFile,
|
||||
$"-o:{resgenFile.OutputFile}",
|
||||
$"\"{resgenFile.InputFile}\"",
|
||||
$"-o:\"{resgenFile.OutputFile}\"",
|
||||
$"-v:{project.Version.Version}"
|
||||
};
|
||||
|
||||
|
@ -71,11 +71,11 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
return false;
|
||||
}
|
||||
|
||||
compilerArgs.Add($"--resource:\"{resgenFile.OutputFile},{Path.GetFileName(resgenFile.MetadataName)}\"");
|
||||
compilerArgs.Add($"--resource:\"{resgenFile.OutputFile}\",{Path.GetFileName(resgenFile.MetadataName)}");
|
||||
}
|
||||
else
|
||||
{
|
||||
compilerArgs.Add($"--resource:\"{resgenFile.InputFile},{Path.GetFileName(resgenFile.MetadataName)}\"");
|
||||
compilerArgs.Add($"--resource:\"{resgenFile.InputFile}\",{Path.GetFileName(resgenFile.MetadataName)}");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
string outputPath)
|
||||
{
|
||||
var referencePaths = CompilerUtil.GetReferencePathsForCultureResgen(dependencies);
|
||||
var resgenReferenceArgs = referencePaths.Select(path => $"-r:{path}").ToList();
|
||||
var resgenReferenceArgs = referencePaths.Select(path => $"-r:\"{path}\"").ToList();
|
||||
var cultureResgenFiles = CompilerUtil.GetCultureResources(project, outputPath);
|
||||
|
||||
foreach (var resgenFile in cultureResgenFiles)
|
||||
|
@ -104,10 +104,10 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
var arguments = new List<string>();
|
||||
|
||||
arguments.AddRange(resgenReferenceArgs);
|
||||
arguments.Add($"-o:{resgenFile.OutputFile}");
|
||||
arguments.Add($"-o:\"{resgenFile.OutputFile}\"");
|
||||
arguments.Add($"-c:{resgenFile.Culture}");
|
||||
arguments.Add($"-v:{project.Version.Version}");
|
||||
arguments.AddRange(resgenFile.InputFileToMetadata.Select(fileToMetadata => $"{fileToMetadata.Key},{fileToMetadata.Value}"));
|
||||
arguments.AddRange(resgenFile.InputFileToMetadata.Select(fileToMetadata => $"\"{fileToMetadata.Key}\",{fileToMetadata.Value}"));
|
||||
var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen.rsp");
|
||||
File.WriteAllLines(rsp, arguments);
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
writer.Write(dependencyContext, fileStream);
|
||||
}
|
||||
|
||||
compilerArgs.Add($"--resource:\"{depsJsonFile},{context.ProjectFile.Name}.deps.json\"");
|
||||
compilerArgs.Add($"--resource:\"{depsJsonFile}\",{context.ProjectFile.Name}.deps.json");
|
||||
}
|
||||
|
||||
if (!AddNonCultureResources(context.ProjectFile, compilerArgs, intermediateOutputPath))
|
||||
|
|
|
@ -19,8 +19,14 @@ namespace Microsoft.DotNet.Tools.Resgen
|
|||
|
||||
public int Execute()
|
||||
{
|
||||
var intputResourceFiles = Args.Select(ParseInputFile).ToArray();
|
||||
var outputResourceFile = ResourceFile.Create(OutputFileName);
|
||||
var inputResourceFiles = Args.Select(ParseInputFile).ToArray();
|
||||
var outputResourceFile = ResourceFile.Create(OutputFileName.Trim('"'));
|
||||
|
||||
var trimmedCompilationReferences = default(string[]);
|
||||
if (CompilationReferences != null)
|
||||
{
|
||||
trimmedCompilationReferences = CompilationReferences.Select(r => r.Trim('"')).ToArray();
|
||||
}
|
||||
|
||||
switch (outputResourceFile.Type)
|
||||
{
|
||||
|
@ -33,22 +39,23 @@ namespace Microsoft.DotNet.Tools.Resgen
|
|||
AssemblyVersion = AssemblyVersion,
|
||||
};
|
||||
|
||||
ResourceAssemblyGenerator.Generate(intputResourceFiles,
|
||||
ResourceAssemblyGenerator.Generate(inputResourceFiles,
|
||||
outputStream,
|
||||
metadata,
|
||||
Path.GetFileNameWithoutExtension(outputResourceFile.File.Name),
|
||||
CompilationReferences.ToArray());
|
||||
trimmedCompilationReferences
|
||||
);
|
||||
}
|
||||
break;
|
||||
case ResourceFileType.Resources:
|
||||
using (var outputStream = outputResourceFile.File.Create())
|
||||
{
|
||||
if (intputResourceFiles.Length > 1)
|
||||
if (inputResourceFiles.Length > 1)
|
||||
{
|
||||
Reporter.Error.WriteLine("Only one input file required when generating .resource output");
|
||||
return 1;
|
||||
}
|
||||
ResourcesFileGenerator.Generate(intputResourceFiles.Single().Resource, outputStream);
|
||||
ResourcesFileGenerator.Generate(inputResourceFiles.Single().Resource, outputStream);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -61,13 +68,13 @@ namespace Microsoft.DotNet.Tools.Resgen
|
|||
|
||||
private static ResourceSource ParseInputFile(string arg)
|
||||
{
|
||||
var seperatorIndex = arg.IndexOf(',');
|
||||
var separatorIndex = arg.IndexOf(',');
|
||||
string name;
|
||||
string metadataName;
|
||||
if (seperatorIndex > 0)
|
||||
if (separatorIndex > 0)
|
||||
{
|
||||
name = arg.Substring(0, seperatorIndex);
|
||||
metadataName = arg.Substring(seperatorIndex + 1);
|
||||
name = arg.Substring(0, separatorIndex);
|
||||
metadataName = arg.Substring(separatorIndex + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -75,6 +82,10 @@ namespace Microsoft.DotNet.Tools.Resgen
|
|||
metadataName = arg;
|
||||
}
|
||||
|
||||
// Remove surrounding quotes
|
||||
name = name.Trim('"');
|
||||
metadataName = metadataName.Trim('"');
|
||||
|
||||
return new ResourceSource(ResourceFile.Create(name), metadataName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Xunit;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Resgen.Tests
|
||||
{
|
||||
public class ResgenTests : TestBase
|
||||
{
|
||||
private readonly string _testProjectsRoot;
|
||||
private readonly TempDirectory _root;
|
||||
|
||||
public ResgenTests()
|
||||
{
|
||||
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
|
||||
_root = Temp.CreateDirectory();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test_Build_Project_with_Resources_with_Space_in_Path_Should_Succeed()
|
||||
{
|
||||
var spaceBufferDirectory = _root.CreateDirectory("space directory");
|
||||
var testAppDir = spaceBufferDirectory.CreateDirectory("TestProjectWithResource");
|
||||
|
||||
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestProjectWithResource"), testAppDir);
|
||||
|
||||
var testProject = GetProjectPath(testAppDir);
|
||||
var buildCommand = new BuildCommand(testProject);
|
||||
|
||||
buildCommand.Execute().Should().Pass();
|
||||
}
|
||||
|
||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||
{
|
||||
foreach (var file in Directory.EnumerateFiles(projectDir))
|
||||
{
|
||||
tempDir.CopyFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetProjectPath(TempDirectory projectDir)
|
||||
{
|
||||
return Path.Combine(projectDir.Path, "project.json");
|
||||
}
|
||||
}
|
||||
}
|
19
test/dotnet-resgen.Tests/dotnet-resgen.Tests.xproj
Normal file
19
test/dotnet-resgen.Tests/dotnet-resgen.Tests.xproj
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>386d412c-003c-47b1-8258-0e35865cb7c4</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Tools.Resgen.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'" />
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
28
test/dotnet-resgen.Tests/project.json
Normal file
28
test/dotnet-resgen.Tests/project.json
Normal file
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23811",
|
||||
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"target": "project"
|
||||
},
|
||||
|
||||
"xunit": "2.1.0",
|
||||
"xunit.netcore.extensions": "1.0.0-prerelease-*",
|
||||
"dotnet-test-xunit": "1.0.0-dev-48273-16"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"imports": "portable-net45+win8"
|
||||
}
|
||||
},
|
||||
|
||||
"content": [
|
||||
"../../TestAssets/TestProjects/TestProjectWithResource/**/*"
|
||||
],
|
||||
|
||||
"testRunner": "xunit"
|
||||
}
|
Loading…
Reference in a new issue