Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Publish with GeneratePackageOnBuild=true #3473

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup>
<_ToolsSettingsFilePath>$(BaseIntermediateOutputPath)DotnetToolSettings.xml</_ToolsSettingsFilePath>
<SuppressDependenciesWhenPacking Condition=" '$(PackAsTool)' == 'true' ">true</SuppressDependenciesWhenPacking>
<_PackToolPublishDependency Condition=" ('$(GeneratePackageOnBuild)' != 'true' and '$(NoBuild)' != 'true') and $(IsPublishable) == 'true' ">_PublishBuildAlternative</_PackToolPublishDependency>
<_PackToolPublishDependency Condition=" ('$(GeneratePackageOnBuild)' == 'true' or '$(NoBuild)' == 'true') and $(IsPublishable) == 'true' ">$(_PublishNoBuildAlternativeDependsOn)</_PackToolPublishDependency>
</PropertyGroup>

<Target Name="PackTool" DependsOnTargets="GenerateToolsSettingsFileFromBuildProperty;Publish;_PackToolValidation" Condition=" '$(PackAsTool)' == 'true' ">
<Target Name="PackTool" DependsOnTargets="GenerateToolsSettingsFileFromBuildProperty;$(_PackToolPublishDependency);_PackToolValidation" Condition=" '$(PackAsTool)' == 'true' ">
<ItemGroup>
<_GeneratedFiles Include="$(PublishDepsFilePath)"/>
<_GeneratedFiles Include="$(PublishRuntimeConfigFilePath)"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ Copyright (c) .NET Foundation. All rights reserved.
GeneratePublishDependencyFile;
BundlePublishDirectory;
</_CorePublishTargets>

<_PublishNoBuildAlternativeDependsOn>$(_BeforePublishNoBuildTargets);$(_CorePublishTargets)</_PublishNoBuildAlternativeDependsOn>
</PropertyGroup>

<Target Name="_PublishBuildAlternative"
Condition="'$(NoBuild)' != 'true' and '$(GeneratePackageOnBuild)' != 'true'"
Condition="'$(NoBuild)' != 'true'"
DependsOnTargets="Build;$(_CorePublishTargets)" />

<Target Name="_PublishNoBuildAlternative"
Condition="'$(NoBuild)' == 'true' or '$(GeneratePackageOnBuild)' == 'true'"
DependsOnTargets="$(_BeforePublishNoBuildTargets);$(_CorePublishTargets)" />
Condition="'$(NoBuild)' == 'true'"
DependsOnTargets="$(_PublishNoBuildAlternativeDependsOn)" />

<Target Name="Publish"
Condition="$(IsPublishable) == 'true'"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Commands;
using NuGet.Packaging;
using Xunit;
using Xunit.Abstractions;
using Microsoft.NET.TestFramework.Assertions;

namespace Microsoft.NET.ToolPack.Tests
{
public class GivenThatWeWantToBuildWithGeneratePackageOnBuildAndPackAsTool : SdkTest
{
public GivenThatWeWantToBuildWithGeneratePackageOnBuildAndPackAsTool(ITestOutputHelper log) : base(log)
{}

[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
public void It_builds_successfully(bool generatePackageOnBuild, bool packAsTool)
{
TestAsset testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld", identifier: generatePackageOnBuild.ToString() + packAsTool.ToString())
.WithSource()
.WithProjectChanges((projectPath, project) =>
{
XNamespace ns = project.Root.Name.Namespace;
XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First();
propertyGroup.Add(new XElement(ns + "GeneratePackageOnBuild", generatePackageOnBuild.ToString()));
propertyGroup.Add(new XElement(ns + "PackAsTool", packAsTool.ToString()));
});

var appProjectDirectory = Path.Combine(testAsset.TestRoot);
var buildCommand = new BuildCommand(Log, appProjectDirectory);

CommandResult result = buildCommand.Execute("/restore");

result.Should()
.Pass();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Commands;
using NuGet.Packaging;
using Xunit;
using Xunit.Abstractions;
using Microsoft.NET.TestFramework.Assertions;

namespace Microsoft.NET.ToolPack.Tests
{
public class GivenThatWeWantToPublishWithGeneratePackageOnBuildAndPackAsTool : SdkTest
{
public GivenThatWeWantToPublishWithGeneratePackageOnBuildAndPackAsTool(ITestOutputHelper log) : base(log)
{}

[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
public void It_publishes_successfully(bool generatePackageOnBuild, bool packAsTool)
{
Console.WriteLine(generatePackageOnBuild.ToString() + packAsTool.ToString());

TestAsset testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld", identifier: generatePackageOnBuild.ToString() + packAsTool.ToString())
.WithSource()
.WithProjectChanges((projectPath, project) =>
{
XNamespace ns = project.Root.Name.Namespace;
XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First();
propertyGroup.Add(new XElement(ns + "GeneratePackageOnBuild", generatePackageOnBuild.ToString()));
propertyGroup.Add(new XElement(ns + "PackAsTool", packAsTool.ToString()));
});

var appProjectDirectory = Path.Combine(testAsset.TestRoot);
var publishCommand = new PublishCommand(Log, appProjectDirectory);

CommandResult result = publishCommand.Execute("/restore");

result.Should()
.Pass();
}

[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
public void It_builds_successfully(bool generatePackageOnBuild, bool packAsTool)
{
TestAsset testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld", identifier: generatePackageOnBuild.ToString() + packAsTool.ToString())
.WithSource()
.WithProjectChanges((projectPath, project) =>
{
XNamespace ns = project.Root.Name.Namespace;
XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First();
propertyGroup.Add(new XElement(ns + "GeneratePackageOnBuild", generatePackageOnBuild.ToString()));
propertyGroup.Add(new XElement(ns + "PackAsTool", packAsTool.ToString()));
});

var appProjectDirectory = Path.Combine(testAsset.TestRoot);
var buildCommand = new BuildCommand(Log, appProjectDirectory);

CommandResult result = buildCommand.Execute("/restore");

result.Should()
.Pass();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@ public void It_builds_and_result_contains_dependencies_dll()
}
}

[Theory(Skip = "https://github.com/dotnet/sdk/issues/3471")]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
[InlineData(true, true)]
public void It_packs_successfully(bool generatePackageOnBuild, bool packAsTool)
{
Console.WriteLine(generatePackageOnBuild.ToString() + packAsTool.ToString());

TestAsset testAsset = _testAssetsManager
.CopyTestAsset("HelloWorld", identifier: generatePackageOnBuild.ToString() + packAsTool.ToString())
.WithSource()
.WithProjectChanges((projectPath, project) =>
{
XNamespace ns = project.Root.Name.Namespace;
XElement propertyGroup = project.Root.Elements(ns + "PropertyGroup").First();
propertyGroup.Add(new XElement(ns + "GeneratePackageOnBuild", generatePackageOnBuild.ToString()));
propertyGroup.Add(new XElement(ns + "PackAsTool", packAsTool.ToString()));
});

var appProjectDirectory = Path.Combine(testAsset.TestRoot);
var packCommand = new PackCommand(Log, appProjectDirectory);

CommandResult result = packCommand.Execute("/restore");

result.Should()
.Pass();
}

private bool IsAppProject(string projectPath)
{
return Path.GetFileNameWithoutExtension(projectPath).Equals(AppName, StringComparison.OrdinalIgnoreCase);
Expand Down