Skip to content

Commit ba82573

Browse files
Create packaging project (#157)
1 parent 33bda06 commit ba82573

File tree

10 files changed

+90
-34
lines changed

10 files changed

+90
-34
lines changed

.github/workflows/publish-package.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ jobs:
2222
6.0.x
2323
global-json-file: 'global.json' # in addition to the 6.0 we need for tests, install "latest"
2424
- name: Release
25-
run: dotnet build --configuration release
25+
run: dotnet build packaging --configuration release
2626
- name: Publish
27-
run: dotnet nuget push "Microsoft.NET.Build.Containers/bin/Release/Microsoft.NET.Build.Containers.*.nupkg" --api-key ${{ secrets.FEED_UPLOAD_TOKEN }} --source "https://nuget.pkg.github.com/dotnet/index.json"
27+
run: dotnet nuget push "packaging/bin/Release/Microsoft.NET.Build.Containers.*.nupkg" --api-key ${{ secrets.FEED_UPLOAD_TOKEN }} --source "https://nuget.pkg.github.com/dotnet/index.json"
Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
4+
<TargetFrameworks>net7.0;net472</TargetFrameworks>
5+
<ImplicitUsings Condition="'$(TargetFramework)' != 'net472'">enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8-
9-
<IsPackable>true</IsPackable>
7+
<LangVersion>preview</LangVersion>
108

119
<TargetsForTfmSpecificBuildOutput>
1210
$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage
1311
</TargetsForTfmSpecificBuildOutput>
1412

15-
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
16-
1713
<!-- Tell the SDK to generate a deps.json file -->
1814
<GenerateDependencyFile>true</GenerateDependencyFile>
1915

20-
<!-- MSBuild tasks shouldn't be referenced. This is by design. -->
21-
<NoWarn>NU5100;NU5128</NoWarn>
22-
<Authors>Microsoft</Authors>
23-
<Company>Microsoft</Company>
24-
<Description>Tasks and targets to natively publish .NET applications as containers.</Description>
25-
<Copyright>&#169; Microsoft Corporation. All rights reserved.</Copyright>
26-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
27-
<PackageProjectUrl>https://github.com/dotnet/sdk-container-builds</PackageProjectUrl>
28-
<RepositoryUrl>https://github.com/dotnet/sdk-container-builds</RepositoryUrl>
29-
<RepositoryType>git</RepositoryType>
30-
<PackageTags>containers;docker;Microsoft.NET.Build.Containers</PackageTags>
31-
<PackageReadmeFile>README.md</PackageReadmeFile>
16+
<!-- Allow the packaging project to use the name `Microsoft.NET.Build.Containers` for the nuget package -->
17+
<Packageid>.</Packageid>
3218

3319
<!-- While in prerelease, ship the symbols to everyone all the time. -->
3420
<DebugType>embedded</DebugType>
@@ -38,10 +24,9 @@
3824
<PackageReference Include="Microsoft.Build.Utilities.Core" PrivateAssets="all" ExcludeAssets="runtime" />
3925
</ItemGroup>
4026

41-
<ItemGroup>
42-
<Content Include="build\Microsoft.NET.Build.Containers.props" Pack="true" PackagePath="build\" />
43-
<Content Include="build\Microsoft.NET.Build.Containers.targets" Pack="true" PackagePath="build\" />
44-
<Content Include="README.md" Pack="true" PackagePath="" />
27+
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
28+
<Compile Remove="*.*" />
29+
<!-- A separate PR will add the required CreateNewImageToolTask file. -->
4530
</ItemGroup>
4631

4732
<!-- This target adds all of our PackageReference and ProjectReference's runtime assets to our package output. -->
@@ -58,8 +43,4 @@
5843
</ItemGroup>
5944
</Target>
6045

61-
<!-- Hacky workaround for the fact that we don't publish the package yet. -->
62-
<Target Name="CopyNupkgToCustomFolder" AfterTargets="Pack">
63-
<Copy SourceFiles="$(OutDir)..\Microsoft.NET.Build.Containers.$(Version).nupkg" DestinationFiles="..\Test.Microsoft.NET.Build.Containers.Filesystem\package\Microsoft.NET.Build.Containers.$(Version).nupkg" />
64-
</Target>
6546
</Project>

System.Containers.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test.Microsoft.NET.Build.Co
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "containerize", "containerize\containerize.csproj", "{151F7937-D2AF-4242-9B6D-81FD5228D132}"
1313
EndProject
14+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "package", "packaging\package.csproj", "{570F93C7-E96A-4051-ADCD-1A237015E31A}"
15+
EndProject
16+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "packaging", "packaging", "{E9DE8514-E046-43F4-8831-A42E15492E63}"
17+
EndProject
1418
Global
1519
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1620
Debug|Any CPU = Debug|Any CPU
@@ -33,10 +37,17 @@ Global
3337
{151F7937-D2AF-4242-9B6D-81FD5228D132}.Debug|Any CPU.Build.0 = Debug|Any CPU
3438
{151F7937-D2AF-4242-9B6D-81FD5228D132}.Release|Any CPU.ActiveCfg = Release|Any CPU
3539
{151F7937-D2AF-4242-9B6D-81FD5228D132}.Release|Any CPU.Build.0 = Release|Any CPU
40+
{570F93C7-E96A-4051-ADCD-1A237015E31A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{570F93C7-E96A-4051-ADCD-1A237015E31A}.Debug|Any CPU.Build.0 = Debug|Any CPU
42+
{570F93C7-E96A-4051-ADCD-1A237015E31A}.Release|Any CPU.ActiveCfg = Release|Any CPU
43+
{570F93C7-E96A-4051-ADCD-1A237015E31A}.Release|Any CPU.Build.0 = Release|Any CPU
3644
EndGlobalSection
3745
GlobalSection(SolutionProperties) = preSolution
3846
HideSolutionNode = FALSE
3947
EndGlobalSection
48+
GlobalSection(NestedProjects) = preSolution
49+
{570F93C7-E96A-4051-ADCD-1A237015E31A} = {E9DE8514-E046-43F4-8831-A42E15492E63}
50+
EndGlobalSection
4051
GlobalSection(ExtensibilityGlobals) = postSolution
4152
SolutionGuid = {D68F4804-C298-48F6-9993-8CB75A141BD3}
4253
EndGlobalSection

Test.Microsoft.NET.Build.Containers.Filesystem/EndToEnd.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public async Task EndToEnd_NoAPI()
182182
}
183183

184184
// Add package to the project
185-
info.Arguments = $"add package Microsoft.NET.Build.Containers --prerelease";
185+
info.Arguments = $"add package Microsoft.NET.Build.Containers --prerelease -f net7.0";
186186
Process dotnetPackageAdd = Process.Start(info);
187187
Assert.IsNotNull(dotnetPackageAdd);
188188
await dotnetPackageAdd.WaitForExitAsync();

Test.Microsoft.NET.Build.Containers.Filesystem/TargetsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void LocateMSBuild(TestContext ctx)
2727
{
2828
var instances = MSBuildLocator.QueryVisualStudioInstances(new() { DiscoveryTypes = DiscoveryType.DotNetSdk, WorkingDirectory = Environment.CurrentDirectory });
2929
MSBuildLocator.RegisterInstance(instances.First());
30-
var relativePath = Path.Combine("..", "Microsoft.NET.Build.Containers", "build", "Microsoft.NET.Build.Containers.targets");
30+
var relativePath = Path.Combine("..", "packaging", "build", "Microsoft.NET.Build.Containers.targets");
3131
var targetsFile = CurrentFile.Relative(relativePath);
3232
var propsFile = Path.ChangeExtension(targetsFile, ".props");
3333
CombinedTargetsLocation = CombineFiles(propsFile, targetsFile);

containerize/containerize.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</ItemGroup>
1313

1414
<ItemGroup>
15-
<ProjectReference Include="..\Microsoft.NET.Build.Containers\Microsoft.NET.Build.Containers.csproj" />
15+
<ProjectReference Include="..\Microsoft.NET.Build.Containers\Microsoft.NET.Build.Containers.csproj"/>
1616
</ItemGroup>
1717

1818
</Project>
File renamed without changes.

Microsoft.NET.Build.Containers/build/Microsoft.NET.Build.Containers.props renamed to packaging/build/Microsoft.NET.Build.Containers.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project>
22
<PropertyGroup>
3-
<taskForldername>tasks</taskForldername>
3+
<taskFoldername>tasks</taskFoldername>
44
<taskFramework>net7.0</taskFramework>
55
<!--The folder where the custom task will be present. It points to inside the nuget package. -->
6-
<CustomTasksFolder>$(MSBuildThisFileDirectory)..\$(taskForldername)\$(taskFramework)</CustomTasksFolder>
6+
<CustomTasksFolder>$(MSBuildThisFileDirectory)..\$(taskFoldername)\$(taskFramework)</CustomTasksFolder>
77
<!--Reference to the assembly which contains the MSBuild Task-->
88
<CustomTasksAssembly Condition="'$(CustomTasksAssembly)' == ''">$(CustomTasksFolder)\$(MSBuildThisFileName).dll</CustomTasksAssembly>
99
</PropertyGroup>

packaging/package.csproj

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<Project Sdk="Microsoft.Build.NoTargets/3.5.6">
2+
<PropertyGroup>
3+
<TargetFramework>net7.0</TargetFramework>
4+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
5+
<IsPackable>true</IsPackable>
6+
<NoWarn>NU5100;NU5128</NoWarn>
7+
<VSCompatTargetFramework>net472</VSCompatTargetFramework>
8+
9+
<!-- MSBuild tasks shouldn't be referenced. This is by design. -->
10+
<NoWarn>NU5100;NU5128</NoWarn>
11+
<Authors>Microsoft</Authors>
12+
<Company>Microsoft</Company>
13+
<PackageId>Microsoft.NET.Build.Containers</PackageId>
14+
<Description>Tasks and targets to natively publish .NET applications as containers.</Description>
15+
<Copyright>&#169; Microsoft Corporation. All rights reserved.</Copyright>
16+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
17+
<PackageProjectUrl>https://github.com/dotnet/sdk-container-builds</PackageProjectUrl>
18+
<RepositoryUrl>https://github.com/dotnet/sdk-container-builds</RepositoryUrl>
19+
<RepositoryType>git</RepositoryType>
20+
<PackageTags>containers;docker;Microsoft.NET.Build.Containers</PackageTags>
21+
<PackageReadmeFile>README.md</PackageReadmeFile>
22+
</PropertyGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="../Microsoft.NET.Build.Containers/Microsoft.NET.Build.Containers.csproj"
26+
SetTargetFramework="TargetFramework=$(TargetFramework)"
27+
OutputItemType="ContainerLibraryOutput"/>
28+
29+
<ProjectReference Include="../Microsoft.NET.Build.Containers/Microsoft.NET.Build.Containers.csproj"
30+
SetTargetFramework="TargetFramework=$(VSCompatTargetFramework)"
31+
OutputItemType="ContainerLibraryOutputNet472"/>
32+
33+
<ProjectReference Include="../containerize/containerize.csproj" PrivateAssets="all" ReferenceOutputAssembly="true" />
34+
<PackageReference Include="System.CommandLine" PrivateAssets="all" IncludeAssets="runtime"/>
35+
</ItemGroup>
36+
37+
<Target Name="AddItemsForPackaging" AfterTargets="Build">
38+
<ItemGroup>
39+
<!-- root folder -->
40+
<Content Include="README.md" Pack="true" PackagePath="" />
41+
42+
<!-- containerize folder -->
43+
<Content Include="$(OutDir)containerize.dll" Pack="true" PackagePath="containerize/" />
44+
<Content Include="$(OutDir)containerize.runtimeconfig.json" Pack="true" PackagePath="containerize/" />
45+
<Content Include="$(OutDir)System.CommandLine.dll" Pack="true" PackagePath="containerize/" />
46+
<Content Include="@(ContainerLibraryOutput)" Pack="true" PackagePath="containerize/" />
47+
48+
<!-- tasks folder -->
49+
<Content Include="@(ContainerLibraryOutput)" Pack="true" PackagePath="tasks/$(TargetFramework)/" />
50+
<Content Include="@(ContainerLibraryOutputNet472)" Pack="true" PackagePath="tasks/$(VSCompatTargetFramework)/" />
51+
<Content Include="../Microsoft.NET.Build.Containers/bin/$(Configuration)/$(TargetFramework)/Microsoft.NET.Build.Containers.deps.json" Pack="true" PackagePath="tasks/$(TargetFramework)" />
52+
<Content Include="../Microsoft.NET.Build.Containers/bin/$(Configuration)/$(VSCompatTargetFramework)/Microsoft.NET.Build.Containers.deps.json" Pack="true" PackagePath="tasks/$(VSCompatTargetFramework)" />
53+
54+
<!-- build folder -->
55+
<Content Include="build/**" Pack="true" PackagePath="build/" />
56+
</ItemGroup>
57+
</Target>
58+
59+
<!-- Hacky workaround for the fact that we don't publish the package yet. -->
60+
<Target Name="CopyNupkgToCustomFolder" AfterTargets="Pack">
61+
<Copy SourceFiles="$(OutDir)../Microsoft.NET.Build.Containers.$(Version).nupkg"
62+
DestinationFiles="../Test.Microsoft.NET.Build.Containers.Filesystem/package/Microsoft.NET.Build.Containers.$(Version).nupkg" />
63+
</Target>
64+
</Project>

0 commit comments

Comments
 (0)