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_outputNameTemplate = new OptionTemplate("output-name");
|
||||
|
||||
public static CommonCompilerOptions Parse(ArgumentSyntax syntax)
|
||||
{
|
||||
IReadOnlyList<string> defines = null;
|
||||
|
@ -55,6 +57,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
|||
bool? publicSign = null;
|
||||
bool? emitEntryPoint = null;
|
||||
bool? generateXmlDocumentation = null;
|
||||
string outputName = null;
|
||||
IReadOnlyList<string> additionalArguments = null;
|
||||
|
||||
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,
|
||||
nullableBoolConverter, "Generate XML documentation file");
|
||||
|
||||
syntax.DefineOption(s_outputNameTemplate.LongName, ref outputName, "Output assembly name");
|
||||
|
||||
return new CommonCompilerOptions
|
||||
{
|
||||
Defines = defines,
|
||||
|
@ -112,6 +117,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
|||
DebugType = debugType,
|
||||
EmitEntryPoint = emitEntryPoint,
|
||||
GenerateXmlDocumentation = generateXmlDocumentation,
|
||||
OutputName = outputName,
|
||||
AdditionalArguments = additionalArguments
|
||||
};
|
||||
}
|
||||
|
@ -131,6 +137,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
|||
var publicSign = options.PublicSign;
|
||||
var emitEntryPoint = options.EmitEntryPoint;
|
||||
var generateXmlDocumentation = options.GenerateXmlDocumentation;
|
||||
var outputName = options.OutputName;
|
||||
var additionalArguments = options.AdditionalArguments;
|
||||
|
||||
var args = new List<string>();
|
||||
|
@ -205,6 +212,11 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
|||
args.Add(s_generateXmlDocumentation.ToLongArg(generateXmlDocumentation));
|
||||
}
|
||||
|
||||
if (outputName != null)
|
||||
{
|
||||
args.Add(s_outputNameTemplate.ToLongArg(outputName));
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
public IEnumerable<string> AdditionalArguments { get; set; }
|
||||
|
||||
public string OutputName { get;set; }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var other = obj as CommonCompilerOptions;
|
||||
|
@ -57,7 +59,8 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
PreserveCompilationContext == other.PreserveCompilationContext &&
|
||||
EnumerableEquals(Defines, other.Defines) &&
|
||||
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)
|
||||
|
@ -153,6 +156,11 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
{
|
||||
result.GenerateXmlDocumentation = option.GenerateXmlDocumentation;
|
||||
}
|
||||
|
||||
if (option.OutputName != null)
|
||||
{
|
||||
result.OutputName = option.OutputName;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -40,9 +40,11 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
{
|
||||
get
|
||||
{
|
||||
var compilationOptions = Project.GetCompilerOptions(Framework, Configuration);
|
||||
|
||||
return Path.Combine(
|
||||
BasePath,
|
||||
Project.Name + OutputExtension);
|
||||
(compilationOptions.OutputName ?? Project.Name) + OutputExtension);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -575,7 +575,8 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
DebugType = rawOptions.ValueAsString("debugType"),
|
||||
EmitEntryPoint = rawOptions.ValueAsNullableBoolean("emitEntryPoint"),
|
||||
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
|
||||
{
|
||||
protected ArtifactPathsCalculator ArtifactPathsCalculator { get; }
|
||||
|
||||
|
||||
protected Project Project { get; }
|
||||
|
||||
protected string Configuration { get; }
|
||||
|
@ -38,7 +38,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
ArtifactPathsCalculator = artifactPathsCalculator;
|
||||
Project = project;
|
||||
Configuration = configuration;
|
||||
}
|
||||
}
|
||||
|
||||
public bool BuildPackage(IEnumerable<ProjectContext> contexts, List<DiagnosticMessage> packDiagnostics)
|
||||
{
|
||||
|
@ -323,7 +323,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
}
|
||||
|
||||
return Project.Name + outputExtension;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetDefaultRootOutputPath(Project project, string outputOptionValue)
|
||||
{
|
||||
|
|
|
@ -74,20 +74,20 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
|
||||
[Fact]
|
||||
public void LibraryWithAnalyzer()
|
||||
{
|
||||
{
|
||||
var root = Temp.CreateDirectory();
|
||||
var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
|
||||
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer");
|
||||
|
||||
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
|
||||
|
||||
|
||||
// run compile
|
||||
var outputDir = Path.Combine(testLibDir.Path, "bin");
|
||||
var testProject = GetProjectPath(testLibDir);
|
||||
var buildCmd = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
|
||||
var result = buildCmd.ExecuteWithCapturedOutput();
|
||||
result.Should().Pass();
|
||||
|
||||
|
||||
Assert.Contains("CA1018", result.StdErr);
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
|
||||
var testProjectDir = Path.Combine(_testProjectsRoot, "TestAppCompilationContext", "TestApp");
|
||||
var testProject = Path.Combine(testProjectDir, "project.json");
|
||||
|
||||
|
||||
var buildCommand = new BuildCommand(testProject);
|
||||
|
||||
buildCommand.Execute().Should().Pass();
|
||||
|
@ -167,6 +167,24 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
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)
|
||||
{
|
||||
// copy all the files to temp dir
|
||||
|
|
Loading…
Reference in a new issue