Publish can skip Build
This commit is contained in:
parent
090336d785
commit
ded82caccd
4 changed files with 68 additions and 30 deletions
|
@ -28,6 +28,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
|
||||
var projectPath = app.Argument("<PROJECT>", "The project to publish, defaults to the current directory. Can be a path to a project.json or a project directory");
|
||||
var nativeSubdirectories = app.Option("--native-subdirectory", "Temporary mechanism to include subdirectories from native assets of dependency packages in output", CommandOptionType.NoValue);
|
||||
var noBuild = app.Option("--no-build", "Do not build projects before publishing", CommandOptionType.NoValue);
|
||||
|
||||
app.OnExecute(() =>
|
||||
{
|
||||
|
@ -41,6 +42,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
publish.NativeSubdirectories = nativeSubdirectories.HasValue();
|
||||
publish.ProjectPath = projectPath.Value;
|
||||
publish.VersionSuffix = versionSuffix.Value();
|
||||
publish.ShouldBuild = !noBuild.HasValue();
|
||||
|
||||
if (string.IsNullOrEmpty(publish.ProjectPath))
|
||||
{
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
public string VersionSuffix { get; set; }
|
||||
public int NumberOfProjects { get; private set; }
|
||||
public int NumberOfPublishedProjects { get; private set; }
|
||||
public bool ShouldBuild { get; set; }
|
||||
|
||||
public bool TryPrepareForPublish()
|
||||
{
|
||||
|
@ -119,34 +120,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
}
|
||||
|
||||
// Compile the project (and transitively, all it's dependencies)
|
||||
var args = new List<string>() {
|
||||
"--framework",
|
||||
$"{context.TargetFramework.DotNetFrameworkName}",
|
||||
"--configuration",
|
||||
configuration,
|
||||
context.ProjectFile.ProjectDirectory
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(context.RuntimeIdentifier))
|
||||
{
|
||||
args.Insert(0, context.RuntimeIdentifier);
|
||||
args.Insert(0, "--runtime");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(VersionSuffix))
|
||||
{
|
||||
args.Add("--version-suffix");
|
||||
args.Add(VersionSuffix);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(buildBasePath))
|
||||
{
|
||||
args.Add("--build-base-path");
|
||||
args.Add(buildBasePath);
|
||||
}
|
||||
|
||||
var result = Build.BuildCommand.Run(args.ToArray());
|
||||
if (result != 0)
|
||||
if (ShouldBuild && !InvokeBuildOnProject(context, buildBasePath, configuration))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -206,6 +180,40 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
return true;
|
||||
}
|
||||
|
||||
private Boolean InvokeBuildOnProject(ProjectContext context, String buildBasePath, String configuration)
|
||||
{
|
||||
var args = new List<string>()
|
||||
{
|
||||
"--framework",
|
||||
$"{context.TargetFramework.DotNetFrameworkName}",
|
||||
"--configuration",
|
||||
configuration,
|
||||
context.ProjectFile.ProjectDirectory
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(context.RuntimeIdentifier))
|
||||
{
|
||||
args.Insert(0, context.RuntimeIdentifier);
|
||||
args.Insert(0, "--runtime");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(VersionSuffix))
|
||||
{
|
||||
args.Add("--version-suffix");
|
||||
args.Add(VersionSuffix);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(buildBasePath))
|
||||
{
|
||||
args.Add("--build-base-path");
|
||||
args.Add(buildBasePath);
|
||||
}
|
||||
|
||||
var result = Build.BuildCommand.Run(args.ToArray());
|
||||
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
private HashSet<string> GetExclusionList(ProjectContext context, Dictionary<string, LibraryExport> exports)
|
||||
{
|
||||
var exclusionList = new HashSet<string>();
|
||||
|
|
|
@ -19,9 +19,10 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
private readonly string _framework;
|
||||
private readonly string _runtime;
|
||||
private readonly string _config;
|
||||
private readonly bool _noBuild;
|
||||
private readonly string _output;
|
||||
|
||||
public PublishCommand(string projectPath, string framework = "", string runtime = "", string output = "", string config = "", bool forcePortable = false)
|
||||
public PublishCommand(string projectPath, string framework = "", string runtime = "", string output = "", string config = "", bool forcePortable = false, bool noBuild = false)
|
||||
: base("dotnet")
|
||||
{
|
||||
_path = projectPath;
|
||||
|
@ -30,6 +31,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
_runtime = runtime;
|
||||
_output = output;
|
||||
_config = config;
|
||||
_noBuild = noBuild;
|
||||
}
|
||||
|
||||
public override CommandResult Execute(string args = "")
|
||||
|
@ -91,12 +93,13 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
|
||||
private string BuildArgs()
|
||||
{
|
||||
return $"{_path} {FrameworkOption} {RuntimeOption} {OutputOption} {ConfigOption}";
|
||||
return $"{_path} {FrameworkOption} {RuntimeOption} {OutputOption} {ConfigOption} {NoBuildFlag}";
|
||||
}
|
||||
|
||||
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
|
||||
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
|
||||
private string OutputOption => string.IsNullOrEmpty(_output) ? "" : $"-o \"{_output}\"";
|
||||
private string ConfigOption => string.IsNullOrEmpty(_config) ? "" : $"-c {_output}";
|
||||
private string NoBuildFlag => _noBuild ? "--no-build" :"";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,6 +176,31 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
publishCommand.Execute().Should().Fail();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PublishFailsWhenProjectNotBuiltAndNoBuildFlagSet()
|
||||
{
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppCompilationContext")
|
||||
.WithLockFiles();
|
||||
|
||||
var testProject = _getProjectJson(instance.TestRoot, "TestApp");
|
||||
var publishCommand = new PublishCommand(testProject, noBuild: true);
|
||||
|
||||
publishCommand.Execute().Should().Fail();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PublishSucceedsWhenProjectPreviouslyCompiledAndNoBuildFlagSet()
|
||||
{
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppCompilationContext")
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
|
||||
var testProject = _getProjectJson(instance.TestRoot, "TestApp");
|
||||
var publishCommand = new PublishCommand(testProject, noBuild: true);
|
||||
|
||||
publishCommand.Execute().Should().Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PublishScriptsRun()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue