-
Notifications
You must be signed in to change notification settings - Fork 65
Add build helpers for NuGet packages #345
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f044fca
Add build helpers for NuGet packages
twsouthwick 8e5a81d
Merge remote-tracking branch 'origin/main' into tasou/nuget-content-f…
twsouthwick e350613
use property
twsouthwick 83d2d9b
Remove extra group
twsouthwick 7c4c1aa
fix casing
twsouthwick 641c1e6
fix test
twsouthwick 3f47d74
handle pathing difference
twsouthwick 4eaccf7
order output
twsouthwick 30fe083
add header
twsouthwick 1c53776
Update src/Microsoft.AspNetCore.SystemWebAdapters/Build/NuGetContentF…
twsouthwick 9bb35e4
Update message
twsouthwick 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
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
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
1 change: 1 addition & 0 deletions
1
...Microsoft.AspNetCore.SystemWebAdapters/Build/Microsoft.AspNetCore.SystemWebAdapters.props
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 @@ | ||
<Project /> |
3 changes: 3 additions & 0 deletions
3
...crosoft.AspNetCore.SystemWebAdapters/Build/Microsoft.AspNetCore.SystemWebAdapters.targets
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,3 @@ | ||
<Project> | ||
<Import Project="$(MSBuildThisFileDirectory)NuGetContentFiles.targets"/> | ||
</Project> |
53 changes: 53 additions & 0 deletions
53
src/Microsoft.AspNetCore.SystemWebAdapters/Build/NuGetContentFiles.targets
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,53 @@ | ||
<Project> | ||
|
||
<!-- | ||
Add NuGet content to the build output if specified: | ||
<PackageReference Include="..." CopyContent="true" ... /> | ||
--> | ||
<Target Name="AddNugetContentFiles" BeforeTargets="AssignTargetPaths"> | ||
|
||
<!-- Identity PackageReference and paths to packages --> | ||
<ItemGroup> | ||
<_PackageReferenceProperties Include="Pkg$([System.String]::Copy('%(PackageReference.Identity)').Replace('.','_'))"> | ||
<PackageName>%(PackageReference.Identity)</PackageName> | ||
<CopyContent>%(PackageReference.CopyContent)</CopyContent> | ||
</_PackageReferenceProperties> | ||
<_PackageReferenceProperties Update="@(_PackageReferenceProperties)" PackageRootPath="$(%(_PackageReferenceProperties.Identity))" /> | ||
<_PackageReferenceCopyContent Include="@(_PackageReferenceProperties)" Condition="'%(CopyContent)' == 'true'" /> | ||
twsouthwick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</ItemGroup> | ||
|
||
<!-- Check for tools files --> | ||
<ItemGroup> | ||
<_ToolsFiles Include="%(_PackageReferenceCopyContent.PackageRootPath)/tools/*.ps1"> | ||
<PackageName>%(PackageName)</PackageName> | ||
</_ToolsFiles> | ||
<_ToolsPackage Include="%(_ToolsFiles.PackageName)" /> | ||
</ItemGroup> | ||
|
||
<!-- Get content files--> | ||
<ItemGroup> | ||
<_ContentPkgProperties Include="@(_PackageReferenceCopyContent)" /> | ||
|
||
<!-- Filter out packages that need GeneratePathProperty --> | ||
<_ValidContentPkgProperties Include="@(_ContentPkgProperties)" Condition=" '%(PackageRootPath)' != '' " /> | ||
<_InvalidContentPkgProperties Include="@(_ContentPkgProperties)" Condition=" '%(PackageRootPath)' == '' " /> | ||
</ItemGroup> | ||
|
||
<Warning | ||
Condition=" '@(_InvalidContentPkgProperties)' != '' " | ||
Text="The PackageReference '%(_InvalidContentPkgProperties.PackageName)' must specify the attribute 'GeneratePathProperty="true"' when CopyContent is enabled." /> | ||
|
||
<ItemGroup Condition=" '@(_ValidContentPkgProperties)' != '' "> | ||
<_NuGetContentFiles Include="%(_ValidContentPkgProperties.PackageRootPath)\Content\**\*"> | ||
<BasePath>%(_ValidContentPkgProperties.PackageRootPath)\Content</BasePath> | ||
<PackageIdentity>%(_ValidContentPkgProperties.PackageName)</PackageIdentity> | ||
</_NuGetContentFiles> | ||
|
||
<Content Include="@(_NuGetContentFiles)"> | ||
jeffkl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Link>$([MSBuild]::MakeRelative(%(_NuGetContentFiles.BasePath),%(_NuGetContentFiles.Identity)))</Link> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
|
||
</Target> | ||
</Project> |
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
34 changes: 34 additions & 0 deletions
34
test/Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests/ContentFileTests.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,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests; | ||
|
||
public class ContentFileTests | ||
{ | ||
[Fact] | ||
public void ContentFilesCopied() | ||
{ | ||
// Arrange | ||
var expected = new[] | ||
{ | ||
Path.Combine("Scripts", "jquery-3.5.1-vsdoc.js"), | ||
Path.Combine("Scripts", "jquery-3.5.1.js"), | ||
Path.Combine("Scripts", "jquery-3.5.1.min.js"), | ||
Path.Combine("Scripts", "jquery-3.5.1.min.map"), | ||
Path.Combine("Scripts", "jquery-3.5.1.slim.js"), | ||
Path.Combine("Scripts", "jquery-3.5.1.slim.min.js"), | ||
Path.Combine("Scripts", "jquery-3.5.1.slim.min.map"), | ||
}; | ||
|
||
// Act | ||
var files = Directory.GetFiles("Scripts"); | ||
|
||
// Assert | ||
Assert.Equal(expected.Order(StringComparer.Ordinal), files.Order(StringComparer.Ordinal)); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...e.SystemWebAdapters.NuGet.Tests/Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests.csproj
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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="$(SolutionRootDirectory)src/Microsoft.AspNetCore.SystemWebAdapters/Build/Microsoft.AspNetCore.SystemWebAdapters.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>net8.0</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Autofac.Extras.Moq" Version="6.0.0" /> | ||
<PackageReference Include="AutoFixture" Version="4.15.0" /> | ||
<PackageReference Include="Moq" Version="4.16.1" /> | ||
</ItemGroup> | ||
|
||
<!-- Used for tests but not directly --> | ||
<ItemGroup> | ||
<PackageReference Include="jQuery" Version="3.5.1" CopyContent="true" /> | ||
</ItemGroup> | ||
|
||
<Import Project="$(SolutionRootDirectory)src/Microsoft.AspNetCore.SystemWebAdapters/Build/Microsoft.AspNetCore.SystemWebAdapters.targets" /> | ||
|
||
</Project> |
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.
FYI @rainersigwald so he can see this beautiful hackery 😄