Skip to content

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 11 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
</PropertyGroup>

<PropertyGroup>
<SolutionRootDirectory>$(MSBuildThisFileDirectory)</SolutionRootDirectory>
</PropertyGroup>

<PropertyGroup Label="Package and Assembly Metadata">
<Product>Microsoft ASP.NET Core</Product>
</PropertyGroup>
Expand Down
7 changes: 7 additions & 0 deletions Microsoft.AspNetCore.SystemWebAdapters.sln
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModulesFramework", "samples
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModulesCore", "samples\Modules\ModulesCore\ModulesCore.csproj", "{F8B33C59-27CF-45DC-955C-2EBF9DA9DB7E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests", "test\Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests\Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests.csproj", "{17055F45-E79A-41EF-825E-0B2211433729}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -185,6 +187,10 @@ Global
{F8B33C59-27CF-45DC-955C-2EBF9DA9DB7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8B33C59-27CF-45DC-955C-2EBF9DA9DB7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8B33C59-27CF-45DC-955C-2EBF9DA9DB7E}.Release|Any CPU.Build.0 = Release|Any CPU
{17055F45-E79A-41EF-825E-0B2211433729}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{17055F45-E79A-41EF-825E-0B2211433729}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17055F45-E79A-41EF-825E-0B2211433729}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17055F45-E79A-41EF-825E-0B2211433729}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -221,6 +227,7 @@ Global
{5597A485-4D9B-4CE6-A489-DEBE9338450F} = {4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C}
{B262AD69-11F0-4AE0-949A-AEAA2300C061} = {4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C}
{F8B33C59-27CF-45DC-955C-2EBF9DA9DB7E} = {4ED7A31C-8DBE-4A32-A17A-D72794F9FE2C}
{17055F45-E79A-41EF-825E-0B2211433729} = {A1BDA50C-D70B-416C-97F1-74B0649797C5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DABA3C65-9D74-4EB6-9B1C-730328710EAD}
Expand Down
1 change: 1 addition & 0 deletions Microsoft.AspNetCore.SystemWebAdapters.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test\\Microsoft.AspNetCore.SystemWebAdapters.CoreServices.Tests\\Microsoft.AspNetCore.SystemWebAdapters.CoreServices.Tests.csproj",
"test\\Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.Tests\\Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices.Tests.csproj",
"test\\Microsoft.AspNetCore.SystemWebAdapters.Tests\\Microsoft.AspNetCore.SystemWebAdapters.Tests.csproj",
"test\\Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests\\Microsoft.AspNetCore.SystemWebAdapters.NuGet.Tests.csproj",
"test\\Samples.MVCApp.Tests\\Samples.MVCApp.Tests.csproj",
"test\\Samples.RemoteAuth.Forms.Tests\\Samples.RemoteAuth.Forms.Tests.csproj"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Project />
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)NuGetContentFiles.targets"/>
</Project>
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>
Copy link

@jeffkl jeffkl Oct 13, 2023

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 😄

<_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'" />
</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=&quot;true&quot;' 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)">
<Link>$([MSBuild]::MakeRelative(%(_NuGetContentFiles.BasePath),%(_NuGetContentFiles.Identity)))</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
<Reference Include="System.Web" />
</ItemGroup>

<ItemGroup>
<None Include="Build\*" Pack="true" PackagePath="Build\" />
</ItemGroup>

<Import Condition=" '$(TargetFramework)' == 'net6.0' " Project="Generated/GenerateApis.targets" />

</Project>
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));
}
}
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>