Skip to content

Commit 37f6666

Browse files
author
William Li
authored
Exe do not inclue app package (#2395)
* Packing a .NET Core Exe shouldn't include package dependency on Microsoft.NETCore.App
1 parent 8ccd838 commit 37f6666

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ Copyright (c) .NET Foundation. All rights reserved.
4848
<ItemGroup Condition=" '$(DisableImplicitFrameworkReferences)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
4949
<PackageReference Include="Microsoft.NETCore.App" Version="$(RuntimeFrameworkVersion)" IsImplicitlyDefined="true" />
5050

51-
<!-- For libraries targeting .NET Core 2.0 or higher, don't include a dependency on Microsoft.NETCore.App in the package produced by pack.
52-
Packing an app (for example a .NET CLI tool) should include the Microsoft.NETCore.App package dependency. -->
51+
<!-- For targeting .NET Core 2.0 or higher, don't include a dependency on Microsoft.NETCore.App in the package produced by pack.
52+
Packing an DotnetCliTool should include the Microsoft.NETCore.App package dependency. -->
5353
<PackageReference Update="Microsoft.NETCore.App"
54-
Condition="('$(OutputType)' != 'Exe') And ('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '2.0')"
54+
Condition="('$(_TargetFrameworkVersionWithoutV)' != '') And ('$(_TargetFrameworkVersionWithoutV)' >= '2.0') And ('$(PackageType)' != 'DotnetCliTool')"
5555
PrivateAssets="All"
5656
Publish="true" />
5757
</ItemGroup>

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToGenerateADepsFileForATool.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public void It_creates_a_deps_file_for_the_tool_and_the_tool_runs()
4141
IsExe = true
4242
};
4343

44+
toolProject.AdditionalProperties.Add("PackageType", "DotnetCliTool");
45+
4446
GenerateDepsAndRunTool(toolProject)
4547
.Should()
4648
.Pass()
@@ -59,6 +61,8 @@ public void It_handles_conflicts_when_creating_a_tool_deps_file()
5961
IsExe = true
6062
};
6163

64+
toolProject.AdditionalProperties.Add("PackageType", "DotnetCliTool");
65+
6266
toolProject.PackageReferences.Add(new TestPackageReference("Microsoft.Extensions.DependencyModel", "1.1.0", null));
6367

6468
string toolSource = @"

src/Tests/Microsoft.NET.Pack.Tests/GivenThatThereAreImplicitPackageReferences.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void Packing_an_app_exclude_dependencys_framework_assemblies_dependency()
143143
}
144144

145145
[Fact]
146-
public void Packing_a_netcoreapp_2_0_app_includes_the_implicit_dependency()
146+
public void Packing_a_netcoreapp_2_0_app_does_not_include_the_implicit_dependency()
147147
{
148148
TestProject testProject = new TestProject()
149149
{
@@ -155,6 +155,24 @@ public void Packing_a_netcoreapp_2_0_app_includes_the_implicit_dependency()
155155

156156
var dependencies = PackAndGetDependencies(testProject);
157157

158+
dependencies.Should().BeEmpty();
159+
}
160+
161+
[Fact]
162+
public void Packing_a_netcoreapp_2_0_DotnetCliTool_app_includes_the_implicit_dependency()
163+
{
164+
TestProject testProject = new TestProject()
165+
{
166+
Name = "PackNetCoreApp20App",
167+
IsSdkProject = true,
168+
TargetFrameworks = "netcoreapp2.0",
169+
IsExe = true
170+
};
171+
172+
testProject.AdditionalProperties.Add("PackageType", "DotnetCliTool");
173+
174+
var dependencies = PackAndGetDependencies(testProject);
175+
158176
dependencies.Count().Should().Be(1);
159177
dependencies.Single().Attribute("id").Value
160178
.Should().Be("Microsoft.NETCore.App");

0 commit comments

Comments
 (0)