Skip to content

Commit

Permalink
How to add p2p dependencies in a nuget package when using dotnet pack (
Browse files Browse the repository at this point in the history
…#2)

* Adds new transient dependency in the nuget

* Adds hack to include peer dependencies in nuget
  • Loading branch information
johnkors authored Nov 10, 2021
1 parent a9619ca commit 979faec
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
.DS_Store
8 changes: 7 additions & 1 deletion source/DotNetLibrary.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
Expand All @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SomeClassLib", "SomeClassLi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SomeClassLib.Tests", "SomeClassLib.Tests\SomeClassLib.Tests.csproj", "{5DBA7F8C-9688-40CA-A3AD-7028B65FC30E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SomePeerDependency", "SomePeerDependency\SomePeerDependency.csproj", "{7BB23A40-B696-42A8-9610-35A1076182AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,5 +26,9 @@ Global
{5DBA7F8C-9688-40CA-A3AD-7028B65FC30E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DBA7F8C-9688-40CA-A3AD-7028B65FC30E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DBA7F8C-9688-40CA-A3AD-7028B65FC30E}.Release|Any CPU.Build.0 = Release|Any CPU
{7BB23A40-B696-42A8-9610-35A1076182AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7BB23A40-B696-42A8-9610-35A1076182AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7BB23A40-B696-42A8-9610-35A1076182AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7BB23A40-B696-42A8-9610-35A1076182AA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion source/SomeClassLib.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ public class UnitTest1
[Fact]
public void Test1()
{
Assert.Equal("Hello, John", Class1.Greet("John"));
Assert.Equal("Hello, JOHN", Class1.Greet("John"));
}
}
6 changes: 4 additions & 2 deletions source/SomeClassLib/Class1.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace SomeClassLib;
using SomePeerDependency;

namespace SomeClassLib;

public class Class1
{
public static string Greet(string name)
{
return $"Hello, {name}";
return $"Hello, {PeerClass.Upper(name)}";
}
}
13 changes: 13 additions & 0 deletions source/SomeClassLib/SomeClassLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,17 @@
<None Include="../../README.md" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SomePeerDependency\SomePeerDependency.csproj" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeP2PAssets</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="IncludeP2PAssets">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)SomePeerDependency.dll" />
</ItemGroup>
</Target>

</Project>
8 changes: 8 additions & 0 deletions source/SomePeerDependency/PeerClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SomePeerDependency;
public class PeerClass
{
public static string Upper(string text)
{
return text.ToUpper();
}
}
11 changes: 11 additions & 0 deletions source/SomePeerDependency/SomePeerDependency.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

</Project>

0 comments on commit 979faec

Please sign in to comment.