Search code examples
c#git.net-corerider

Git: how manage dependences for your C# libraries?


I write C# apps in Rider and have several self-written libs. These libs builded as .netcore Projects. But there is one lib that use another my libs and it builded as Solution.

And I don't really know how can I use it in my another projects? I just usual clone my lib Project into Solution folder. But this lib is whole Solution too.

How do you solve same problem in your work?


Solution

  • You can build it as NuGet package (Use it from local disk or upload it to NuGet.Org and use it from there)

    To do this:

    Start a Class Library (.Net Standard or .Net Core)

    Configure your .csproj file like this : (example of netcoreapp3.1)

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <Description>Any description here</Description>
        <Authors>Your name here</Authors>
        <Company />
        <PackageProjectUrl>your git hub repo link</PackageProjectUrl>
        <RepositoryUrl>your git hub repo link</RepositoryUrl>
        <RepositoryType>git</RepositoryType>
        <PackageTags>any keywords here with spaces NOT comma</PackageTags>
        <InludeSymbols>true</InludeSymbols>
        <SymbolPackageFormat>snupkg</SymbolPackageFormat>
        <PackageLicenseFile>License.md</PackageLicenseFile>
        <Version>1.0.2</Version>
      </PropertyGroup>
    
      <ItemGroup>
        <None Include="..\..\License.md">
          <Pack>True</Pack>
          <PackagePath></PackagePath>
        </None>
      </ItemGroup>
    </Project>
    

    For this Include="..\..\License.md" you need to add License.md, you can find it online or copy it from your github.

    After you build the project you will find the .nupkg in "\bin\Debug"

    If you like to upload it to NuGet.org :

    1. Register for an account in nuget.org
    2. Upload your package and follow the steps there like add README file and so on, very easy steps.
    3. For projects that need this library, just right click on the project --> manage NuGet package and add this package.

    How to add local Repo as NuGet Source?!

    See this article: How do I install a NuGet package .nupkg file locally?