Create a Nuget package with .Net 5 to wrap a dll

December 3, 2020    DotNet Nuget

Create a Nuget package with .Net 5 to wrap a dll

We’re transitioning to Git and wanting to get the dlls and exes out of our repository (before moving so that it doesn’t keep it in history for ever. See this video about Git LFS for details. Git Lfs seemed too complicated for our team right now).

I found the easiest way was to create a Nuget package with the dll and decided to use .Net 5 that just came out.

.csproj

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFrameworks>net5.0-windows;net452</TargetFrameworks>
        <PackageId>ThePackageName</PackageId>
        <Version>1.0.0</Version>
        <Authors>Kevin Logan</Authors>
        <Company>{YourCompany}</Company>
        <Description>
            This .dll has been in TFVC source control for a long time.
            This package wraps it so we can get it out before moving to Git.
            used dotnet build --configuration Release
            csproj Source is {here}
            nuget.exe push -Source "YourSource" -ApiKey AzureDevOps M.my.nupkg
        </Description>
        <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    </PropertyGroup>
    <ItemGroup>
        <Content Include="The.dll" Pack="true" PackagePath="lib\net5.0-windows7.0\" />
    </ItemGroup>
    <ItemGroup>
        <Content Include="The.dll" Pack="true" PackagePath="lib\net452\" />
    </ItemGroup>
    <ItemGroup>
        <Reference Include="The">
            <HintPath>The.dll</HintPath>
        </Reference>
        <!-- maybe you need to include an old .Net 4.5 dll? I'm not sure this is the best practice-->
        <Reference Include="System.Web.Services">
            <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Web.Services.dll</HintPath>
        </Reference>
    </ItemGroup>
</Project>

creating the .nupkg

just run dotnet build --configuration Release (since true is in the csproj)

or dotnet pack --configuration Release

Upload to your Azure DevOps instance

Click the connect to feed button to see instructions on how to push packages to the repository 1. Download the nuget.exe 2. Copy it to your directory 3. In the command line 4. nuget.exe sources Add -Name “YourSource” -Source “{azdo url}/_packaging/Omnia360Suite/nuget/v3/index.json” 5. nuget.exe push -Source “YourSource” -ApiKey AzureDevOps my_package.nupkg a. nuget.exe push -Source “YourSource” -ApiKey AzureDevOps {prefix}* (* works)

Azure DevOps Artifacts Docs



comments powered by Disqus

Please consider using Brave and adding me to your payment ledger. Then you won't have to see ads!

Support me and download Brave!

Use Brave