-
Notifications
You must be signed in to change notification settings - Fork 66
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 1 commit
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
3 changes: 3 additions & 0 deletions
3
...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,3 @@ | ||
| <Project> | ||
| <PropertyGroup /> | ||
| </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> |
60 changes: 60 additions & 0 deletions
60
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,60 @@ | ||
| <Project> | ||
|
|
||
| <!-- | ||
| Add NuGet content to the build output if specified: | ||
| <PackageReference Include="..." CopyContent="true" ... /> | ||
| --> | ||
| <Target Name="AddNugetContentFiles" BeforeTargets="AssignTargetPaths"> | ||
| <PropertyGroup> | ||
| <EnableSystemWebAdapterNuGetWarnings Condition=" '$(EnableSystemWebAdapterNuGetWarnings)' == '' ">true</EnableSystemWebAdapterNuGetWarnings> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Identity PackageReference and paths to packages --> | ||
| <ItemGroup> | ||
|
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. FYI @rainersigwald so he can see this beautiful hackery 😄 |
||
| <_PackageReferenceProperties Include="Pkg$([System.String]::Copy('%(PackageReference.Identity)').Replace('.','_'))"> | ||
| <PackageName>%(PackageReference.Identity)</PackageName> | ||
| <CopyContent>%(PackageReference.CopyContent)</CopyContent> | ||
| </_PackageReferenceProperties> | ||
| <_PackageReferenceProperties Update="@(_PackageReferenceProperties)" PackageRootPath="$(%(_PackageReferenceProperties.Identity))" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Check for tools files --> | ||
| <ItemGroup> | ||
| <_ToolsFiles Include="%(_PackageReferenceProperties.PackageRootPath)/tools/*.ps1"> | ||
| <PackageName>%(PackageName)</PackageName> | ||
| </_ToolsFiles> | ||
| <_ToolsPackage Include="%(_ToolsFiles.PackageName)" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- Get content files--> | ||
| <ItemGroup> | ||
| <!-- Get all PackageReferences that have 'CopyContent' == 'true' --> | ||
| <_ContentPkgProperties Include="@(_PackageReferenceProperties)" Condition="'%(CopyContent)' == 'true'" /> | ||
|
|
||
| <!-- Filter out packages that need GeneratePathProperty --> | ||
| <_ValidContentPkgProperties Include="@(_ContentPkgProperties)" Condition=" '%(PackageRootPath)' != '' " /> | ||
| <_InvalidContentPkgProperties Include="@(_ContentPkgProperties)" Condition=" '%(PackageRootPath)' == '' " /> | ||
| </ItemGroup> | ||
|
|
||
| <Warning | ||
| Condition=" '$(EnableSystemWebAdapterNuGetWarnings)' == 'true' AND '@(_InvalidContentPkgProperties)' != '' " | ||
| Text="%(_InvalidContentPkgProperties.PackageName) does not contain a tools directory and thus needs 'GeneratePathProperty' == 'true' " /> | ||
|
|
||
| <Warning | ||
| Condition=" '$(EnableSystemWebAdapterNuGetWarnings)' == 'true' AND '@(_ToolsPackage)' != '' " | ||
| Text="%(_ToolsPackage.Identity) contains PowerShell files that may cause issues when using PackageReference" /> | ||
|
|
||
| <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
42 changes: 42 additions & 0 deletions
42
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,42 @@ | ||
| using System.IO; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests; | ||
|
|
||
| public class ContentFileTests | ||
| { | ||
| [Fact] | ||
| public void ContentFilesCopied() | ||
| { | ||
| // Arrange | ||
| var expected = new[] | ||
| { | ||
| """Scripts\jquery-3.5.1-vsdoc.js""", | ||
| """Scripts\jquery-3.5.1.js""", | ||
| """Scripts\jquery-3.5.1.min.js""", | ||
| """Scripts\jquery-3.5.1.min.map""", | ||
| """Scripts\jquery-3.5.1.slim.js""", | ||
| """Scripts\jquery-3.5.1.slim.min.js""", | ||
| """Scripts\jquery-3.5.1.slim.min.map""", | ||
| }; | ||
|
|
||
| // Act | ||
| var files = Directory.GetFiles("Scripts"); | ||
|
|
||
| // Assert | ||
| Assert.Equal(expected, files); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ToolsFiles() | ||
| { | ||
| // Arrange | ||
| const string Path = "test_tools_output.txt"; | ||
| var content = File.ReadAllLines(Path); | ||
|
|
||
| // Assert | ||
| Assert.Collection( | ||
| content, | ||
| c => Assert.Equal("jQuery", c)); | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
...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,37 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <Import Project="../../src/Microsoft.AspNetCore.SystemWebAdapters/build/Microsoft.AspnetCore.SystemWebAdapters.props" /> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net6.0</TargetFrameworks> | ||
|
|
||
| <!-- Disable due to test --> | ||
| <EnableSystemWebAdapterNuGetWarnings>false</EnableSystemWebAdapterNuGetWarnings> | ||
| </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> | ||
|
|
||
| <Target Name="CopyToolsFilesForTest" AfterTargets="AddNugetContentFiles"> | ||
| <ItemGroup> | ||
| <_TestOutput Include="$(OutDir)test_tools_output.txt" /> | ||
| </ItemGroup> | ||
|
|
||
| <WriteLinesToFile | ||
| File="@(_TestOutput)" | ||
| Lines="@(_ToolsPackage)" | ||
| Overwrite="true" | ||
| Encoding="Unicode"/> | ||
| </Target> | ||
|
|
||
| <Import Project="../../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.
Uh oh!
There was an error while loading. Please reload this page.