-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix tool projects so they don't remove apphosts when publishing (not packing) #49818
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
Open
baronfel
wants to merge
3
commits into
dotnet:main
Choose a base branch
from
baronfel:fix-tool-standalone-publishing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+66
−19
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
test/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAToolProject.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable disable | ||
|
||
using System.Runtime.CompilerServices; | ||
using Microsoft.DotNet.Cli.Utils; | ||
|
||
namespace Microsoft.NET.Publish.Tests | ||
{ | ||
public class GivenThatWeWantToPublishAToolProject : SdkTest | ||
{ | ||
public GivenThatWeWantToPublishAToolProject(ITestOutputHelper log) : base(log) | ||
{ | ||
} | ||
|
||
private TestAsset SetupTestAsset([CallerMemberName] string callingMethod = "") | ||
{ | ||
TestAsset helloWorldAsset = _testAssetsManager | ||
.CopyTestAsset("PortableTool", callingMethod) | ||
.WithSource(); | ||
|
||
|
||
return helloWorldAsset; | ||
} | ||
|
||
[Fact] | ||
// this test verifies that we don't regress the 'normal' publish experience accidentally in the | ||
// PackTool.targets | ||
public void It_can_publish_and_has_apphost() | ||
{ | ||
var testAsset = SetupTestAsset(); | ||
var publishCommand = new PublishCommand(testAsset); | ||
|
||
publishCommand.Execute(); | ||
|
||
publishCommand.GetOutputDirectory(targetFramework: ToolsetInfo.CurrentTargetFramework) | ||
.EnumerateFiles().Should().Contain(f => f.Name == "consoledemo" + Constants.ExeSuffix); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a DirectoryInfo assertion which should give better error messages here. Somethnig like |
||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels flaky to me. We publish before we pack, does this mean that the contents of a normal Publish would be different from a Publish-for-Pack operation? That seems kind of bad and like it would hurt incrementality.
Could we let the app host be created in Publish regardless, but then filter it out of the files that we pack if need be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I actually thing this brings the two outputs into alignment - when publishing an exe you get an apphost by default. When packing a RID-agnostic tool you never want an apphost. Making this explicit on the interior publish seems like a very safe thing to do IMO. It's also pretty ok from an incrementality perspective - the expensive parts of publishing aren't copying an apphost.
Re: your second part - that's an interesting idea. I confess that I find the idea of more explicitly controlling the publish more attractive though - it feels more intentional and less ad-hoc to me. We're publishing for a distinctly different purpose when we pack a tool - it feels right to express that on the parameters to the publish operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have some problems with Publish because in some cases the Build needs to be different depending on whether Publish is going to run. This seems like the same thing, only this time the behavior of Publish needs to be different depending on whether we're going to run Pack or not. That's why this feels off to me and why it seems like it would be better to change the behavior of Pack here than that of Publish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't follow - by definition I am changing the behavior of Pack - Pack wants the published output of the app, but within specific parameters for framework-dependent, rid--agnostic tools. The 'publish' in this case is an implementation detail of packaging the tool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note to self: this thread is about the publish outputs from the users' perspective - that should remain untouched.
We could remove the apphsot as part of packing, publish to an intermediate dir, or something else to solve this in a more clean way.