Skip to content

Instantly share code, notes, and snippets.

@lawrence-laz
Last active June 27, 2023 11:21
Show Gist options
  • Save lawrence-laz/7de9df0d365f0cad05b00a585610139f to your computer and use it in GitHub Desktop.
Save lawrence-laz/7de9df0d365f0cad05b00a585610139f to your computer and use it in GitHub Desktop.
Various examples for common things to do when authoring NuGet packages

Nuget

File build/MyNugetPackage.targets is injected into the MSBuild project that references this nuget package. Here is an example to copy *.dll files and reference them.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <NativeLibs Include="$(MSBuildThisFileDirectory)**\*.dll" />
        <None Include="@(NativeLibs)">
            <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </None>
    </ItemGroup>
    <ItemGroup>
        <Reference Include="MyAssembly">
            <HintPath>MyAssembly.dll</HintPath>
        </Reference>
        <Reference Include="MyOtherAssembly">
            <HintPath>MyOtherAssembly.dll</HintPath>
        </Reference>
    </ItemGroup>
</Project>

Include all output files to package directories.

<Target Name="IncludeAllFilesInTargetDir" AfterTargets="Build">
    <ItemGroup>
        <None Include="$(TargetDir)\**">
            <Pack>true</Pack>
            <PackagePath>lib</PackagePath>
        </None>
        <None Include="$(TargetDir)\**">
            <Pack>true</Pack>
            <PackagePath>build</PackagePath>
        </None>
        <None Include="build/MyPackage.targets">
            <Pack>true</Pack>
            <PackagePath>build</PackagePath>
        </None>
    </ItemGroup>
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment