-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
By default, packing Compile should not include generated files
Like the target framework attribute and assembly info. Additional exclusions should be configurable as needed, so we moved the <PackInference> item to a .props file so the project can update/remove as needed. This adds another customization point too, allowing to tweak the exclusions for any PackInference (i.e. for Content, EmbeddedResource, None and so on).
- Loading branch information
Showing
11 changed files
with
139 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,21 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
NuGetizer.Inference.props | ||
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have | ||
created a backup copy. Incorrect changes to this file will make it | ||
impossible to load or build your projects from the command-line or the IDE. | ||
Copyright (c) .NET Foundation. All rights reserved. | ||
*********************************************************************************************** | ||
--> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<ItemGroup> | ||
<PackInference Include="Compile" PackExclude="$(IntermediateOutputPath)/**/*$(DefaultLanguageSourceExtension)" /> | ||
<PackInference Include="Content;EmbeddedResource;None;ApplicationDefinition;Page; | ||
Resource;SplashScreen;DesignData;DesignDataWithDesignTimeCreatableTypes; | ||
CodeAnalysisDictionary;AndroidAsset;AndroidResource;BundleResource" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Empty file.
Empty file.
18 changes: 18 additions & 0 deletions
18
src/NuGetizer.Tests/Scenarios/given_a_library/library.csproj
This file contains 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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Scenario.props, $(MSBuildThisFileDirectory)))" /> | ||
<PropertyGroup> | ||
<AssemblyName>library</AssemblyName> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<IsPackable>true</IsPackable> | ||
<EnableDefaultItems>true</EnableDefaultItems> | ||
<GenerateAssemblyInfo>true</GenerateAssemblyInfo> | ||
<GenerateTargetFrameworkAttribute>true</GenerateTargetFrameworkAttribute> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<!-- The _._ is added by the scenario targets so that projects aren't entirely empty of compile items --> | ||
<Compile Remove="@(Compile -> WithMetadataValue('Extension', '._'))" /> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(PackOnlyApi)' == 'true'"> | ||
<PackInference Update="Compile" PackExclude="%(PackExclude);*.cs" /> | ||
</ItemGroup> | ||
</Project> |
This file contains 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,58 @@ | ||
using System.IO; | ||
using System.Linq; | ||
using System.ServiceModel.Configuration; | ||
using Microsoft.Build.Execution; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace NuGetizer | ||
{ | ||
public class given_a_library | ||
{ | ||
ITestOutputHelper output; | ||
|
||
public given_a_library(ITestOutputHelper output) | ||
{ | ||
this.output = output; | ||
using var disable = OpenBuildLogAttribute.Disable(); | ||
Builder.BuildScenario(nameof(given_a_library), target: "Restore") | ||
.AssertSuccess(output); | ||
} | ||
|
||
[Fact] | ||
public void when_pack_compile_then_excludes_generated_files() | ||
{ | ||
var result = Builder.BuildScenario(nameof(given_a_library), | ||
new { PackCompile = "true" }, | ||
target: "Build,GetPackageContents,Pack"); | ||
|
||
Assert.True(result.BuildResult.HasResultsForTarget("GetPackageContents")); | ||
|
||
var items = result.BuildResult.ResultsByTarget["GetPackageContents"]; | ||
var compile = items.Items.Where(item => item.Matches(new | ||
{ | ||
BuildAction = "Compile", | ||
})).ToArray(); | ||
|
||
Assert.Equal(2, compile.Length); | ||
} | ||
|
||
[Fact] | ||
public void when_pack_excludes_additional_items_then_contains_only_matching_files() | ||
{ | ||
var result = Builder.BuildScenario(nameof(given_a_library), | ||
new { PackCompile = "true", PackOnlyApi = "true" }, | ||
target: "Build,GetPackageContents,Pack"); | ||
|
||
Assert.True(result.BuildResult.HasResultsForTarget("GetPackageContents")); | ||
|
||
var items = result.BuildResult.ResultsByTarget["GetPackageContents"]; | ||
var compile = items.Items.Where(item => item.Matches(new | ||
{ | ||
BuildAction = "Compile", | ||
})).ToArray(); | ||
|
||
Assert.Single(compile); | ||
} | ||
} | ||
} |