Enable specifying output assembly name in compiler options
Addresses #1797
This commit is contained in:
parent
7c8158746e
commit
856fb8d6d9
8 changed files with 70 additions and 10 deletions
|
@ -0,0 +1,6 @@
|
||||||
|
namespace LibraryWithOutputAssemblyName
|
||||||
|
{
|
||||||
|
public class MyClass
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
"compilationOptions": {
|
||||||
|
"outputName": "MyLibrary"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"NETStandard.Library": "1.0.0-rc2-23901"
|
||||||
|
},
|
||||||
|
"frameworks": {
|
||||||
|
"netstandardapp1.5": {
|
||||||
|
"imports": "dnxcore50"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,6 +40,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
|
|
||||||
internal static readonly OptionTemplate s_additionalArgumentsTemplate = new OptionTemplate("additional-argument");
|
internal static readonly OptionTemplate s_additionalArgumentsTemplate = new OptionTemplate("additional-argument");
|
||||||
|
|
||||||
|
internal static readonly OptionTemplate s_outputNameTemplate = new OptionTemplate("output-name");
|
||||||
|
|
||||||
public static CommonCompilerOptions Parse(ArgumentSyntax syntax)
|
public static CommonCompilerOptions Parse(ArgumentSyntax syntax)
|
||||||
{
|
{
|
||||||
IReadOnlyList<string> defines = null;
|
IReadOnlyList<string> defines = null;
|
||||||
|
@ -55,6 +57,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
bool? publicSign = null;
|
bool? publicSign = null;
|
||||||
bool? emitEntryPoint = null;
|
bool? emitEntryPoint = null;
|
||||||
bool? generateXmlDocumentation = null;
|
bool? generateXmlDocumentation = null;
|
||||||
|
string outputName = null;
|
||||||
IReadOnlyList<string> additionalArguments = null;
|
IReadOnlyList<string> additionalArguments = null;
|
||||||
|
|
||||||
Func<string, bool?> nullableBoolConverter = v => bool.Parse(v);
|
Func<string, bool?> nullableBoolConverter = v => bool.Parse(v);
|
||||||
|
@ -97,6 +100,8 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
syntax.DefineOption(s_generateXmlDocumentation.LongName, ref generateXmlDocumentation,
|
syntax.DefineOption(s_generateXmlDocumentation.LongName, ref generateXmlDocumentation,
|
||||||
nullableBoolConverter, "Generate XML documentation file");
|
nullableBoolConverter, "Generate XML documentation file");
|
||||||
|
|
||||||
|
syntax.DefineOption(s_outputNameTemplate.LongName, ref outputName, "Output assembly name");
|
||||||
|
|
||||||
return new CommonCompilerOptions
|
return new CommonCompilerOptions
|
||||||
{
|
{
|
||||||
Defines = defines,
|
Defines = defines,
|
||||||
|
@ -112,6 +117,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
DebugType = debugType,
|
DebugType = debugType,
|
||||||
EmitEntryPoint = emitEntryPoint,
|
EmitEntryPoint = emitEntryPoint,
|
||||||
GenerateXmlDocumentation = generateXmlDocumentation,
|
GenerateXmlDocumentation = generateXmlDocumentation,
|
||||||
|
OutputName = outputName,
|
||||||
AdditionalArguments = additionalArguments
|
AdditionalArguments = additionalArguments
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -131,6 +137,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
var publicSign = options.PublicSign;
|
var publicSign = options.PublicSign;
|
||||||
var emitEntryPoint = options.EmitEntryPoint;
|
var emitEntryPoint = options.EmitEntryPoint;
|
||||||
var generateXmlDocumentation = options.GenerateXmlDocumentation;
|
var generateXmlDocumentation = options.GenerateXmlDocumentation;
|
||||||
|
var outputName = options.OutputName;
|
||||||
var additionalArguments = options.AdditionalArguments;
|
var additionalArguments = options.AdditionalArguments;
|
||||||
|
|
||||||
var args = new List<string>();
|
var args = new List<string>();
|
||||||
|
@ -205,6 +212,11 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
||||||
args.Add(s_generateXmlDocumentation.ToLongArg(generateXmlDocumentation));
|
args.Add(s_generateXmlDocumentation.ToLongArg(generateXmlDocumentation));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (outputName != null)
|
||||||
|
{
|
||||||
|
args.Add(s_outputNameTemplate.ToLongArg(outputName));
|
||||||
|
}
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
|
|
||||||
public IEnumerable<string> AdditionalArguments { get; set; }
|
public IEnumerable<string> AdditionalArguments { get; set; }
|
||||||
|
|
||||||
|
public string OutputName { get;set; }
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
var other = obj as CommonCompilerOptions;
|
var other = obj as CommonCompilerOptions;
|
||||||
|
@ -57,7 +59,8 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
PreserveCompilationContext == other.PreserveCompilationContext &&
|
PreserveCompilationContext == other.PreserveCompilationContext &&
|
||||||
EnumerableEquals(Defines, other.Defines) &&
|
EnumerableEquals(Defines, other.Defines) &&
|
||||||
EnumerableEquals(SuppressWarnings, other.SuppressWarnings) &&
|
EnumerableEquals(SuppressWarnings, other.SuppressWarnings) &&
|
||||||
EnumerableEquals(AdditionalArguments, other.AdditionalArguments);
|
EnumerableEquals(AdditionalArguments, other.AdditionalArguments) &&
|
||||||
|
OutputName == other.OutputName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool EnumerableEquals(IEnumerable<string> left, IEnumerable<string> right)
|
private static bool EnumerableEquals(IEnumerable<string> left, IEnumerable<string> right)
|
||||||
|
@ -153,6 +156,11 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
{
|
{
|
||||||
result.GenerateXmlDocumentation = option.GenerateXmlDocumentation;
|
result.GenerateXmlDocumentation = option.GenerateXmlDocumentation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (option.OutputName != null)
|
||||||
|
{
|
||||||
|
result.OutputName = option.OutputName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -40,9 +40,11 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
var compilationOptions = Project.GetCompilerOptions(Framework, Configuration);
|
||||||
|
|
||||||
return Path.Combine(
|
return Path.Combine(
|
||||||
BasePath,
|
BasePath,
|
||||||
Project.Name + OutputExtension);
|
(compilationOptions.OutputName ?? Project.Name) + OutputExtension);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -575,7 +575,8 @@ namespace Microsoft.DotNet.ProjectModel
|
||||||
DebugType = rawOptions.ValueAsString("debugType"),
|
DebugType = rawOptions.ValueAsString("debugType"),
|
||||||
EmitEntryPoint = rawOptions.ValueAsNullableBoolean("emitEntryPoint"),
|
EmitEntryPoint = rawOptions.ValueAsNullableBoolean("emitEntryPoint"),
|
||||||
GenerateXmlDocumentation = rawOptions.ValueAsNullableBoolean("xmlDoc"),
|
GenerateXmlDocumentation = rawOptions.ValueAsNullableBoolean("xmlDoc"),
|
||||||
PreserveCompilationContext = rawOptions.ValueAsNullableBoolean("preserveCompilationContext")
|
PreserveCompilationContext = rawOptions.ValueAsNullableBoolean("preserveCompilationContext"),
|
||||||
|
OutputName = rawOptions.ValueAsString("outputName")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
public class PackageGenerator
|
public class PackageGenerator
|
||||||
{
|
{
|
||||||
protected ArtifactPathsCalculator ArtifactPathsCalculator { get; }
|
protected ArtifactPathsCalculator ArtifactPathsCalculator { get; }
|
||||||
|
|
||||||
protected Project Project { get; }
|
protected Project Project { get; }
|
||||||
|
|
||||||
protected string Configuration { get; }
|
protected string Configuration { get; }
|
||||||
|
@ -38,7 +38,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
ArtifactPathsCalculator = artifactPathsCalculator;
|
ArtifactPathsCalculator = artifactPathsCalculator;
|
||||||
Project = project;
|
Project = project;
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool BuildPackage(IEnumerable<ProjectContext> contexts, List<DiagnosticMessage> packDiagnostics)
|
public bool BuildPackage(IEnumerable<ProjectContext> contexts, List<DiagnosticMessage> packDiagnostics)
|
||||||
{
|
{
|
||||||
|
@ -323,7 +323,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
}
|
}
|
||||||
|
|
||||||
return Project.Name + outputExtension;
|
return Project.Name + outputExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetDefaultRootOutputPath(Project project, string outputOptionValue)
|
private static string GetDefaultRootOutputPath(Project project, string outputOptionValue)
|
||||||
{
|
{
|
||||||
|
|
|
@ -74,20 +74,20 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void LibraryWithAnalyzer()
|
public void LibraryWithAnalyzer()
|
||||||
{
|
{
|
||||||
var root = Temp.CreateDirectory();
|
var root = Temp.CreateDirectory();
|
||||||
var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
|
var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
|
||||||
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer");
|
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer");
|
||||||
|
|
||||||
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
||||||
|
|
||||||
// run compile
|
// run compile
|
||||||
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
||||||
var testProject = GetProjectPath(testLibDir);
|
var testProject = GetProjectPath(testLibDir);
|
||||||
var buildCmd = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
|
var buildCmd = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
|
||||||
var result = buildCmd.ExecuteWithCapturedOutput();
|
var result = buildCmd.ExecuteWithCapturedOutput();
|
||||||
result.Should().Pass();
|
result.Should().Pass();
|
||||||
|
|
||||||
Assert.Contains("CA1018", result.StdErr);
|
Assert.Contains("CA1018", result.StdErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
||||||
|
|
||||||
var testProjectDir = Path.Combine(_testProjectsRoot, "TestAppCompilationContext", "TestApp");
|
var testProjectDir = Path.Combine(_testProjectsRoot, "TestAppCompilationContext", "TestApp");
|
||||||
var testProject = Path.Combine(testProjectDir, "project.json");
|
var testProject = Path.Combine(testProjectDir, "project.json");
|
||||||
|
|
||||||
var buildCommand = new BuildCommand(testProject);
|
var buildCommand = new BuildCommand(testProject);
|
||||||
|
|
||||||
buildCommand.Execute().Should().Pass();
|
buildCommand.Execute().Should().Pass();
|
||||||
|
@ -167,6 +167,24 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
||||||
runCommand.Execute().Should().Pass();
|
runCommand.Execute().Should().Pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CanSetOutputAssemblyName()
|
||||||
|
{
|
||||||
|
var testInstance =
|
||||||
|
TestAssetsManager
|
||||||
|
.CreateTestInstance("LibraryWithOutputAssemblyName")
|
||||||
|
.WithLockFiles();
|
||||||
|
|
||||||
|
var root = testInstance.TestRoot;
|
||||||
|
var outputDir = Path.Combine(root, "bin");
|
||||||
|
var testProject = ProjectUtils.GetProjectJson(root, "LibraryWithOutputAssemblyName");
|
||||||
|
var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
|
||||||
|
var result = buildCommand.ExecuteWithCapturedOutput();
|
||||||
|
result.Should().Pass();
|
||||||
|
|
||||||
|
new DirectoryInfo(outputDir).Should().HaveFiles(new [] { "MyLibrary.dll" });
|
||||||
|
}
|
||||||
|
|
||||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||||
{
|
{
|
||||||
// copy all the files to temp dir
|
// copy all the files to temp dir
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue