nwithan8 / blog

https://blog.nateharr.is
1 stars 0 forks source link

Including non-code assets in your NuGet package #1

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Including non-code assets in your NuGet package | Thoughts And Ponderings

I’ve been working on a NuGet package recently, a small library that provides extensions and helper methods for the .NET EasyPost API client library.

http://blog.nateharr.is/2023/01/22/Including-non-code-assets-in-your-NuGet-package.html

nwithan8 commented 1 year ago

Update for this, in terms of using the assets in a separate local test project.

In this case, Project C is a test suite of Project A, with Project A imported into is as a reference:

<ItemGroup>
    <ProjectReference Include="..\ProjectA\ProjectA.csproj" />
</ItemGroup>

Project A contains a folder called "assets" that we want to include in Project C when it runs.

In Project C's .csproj file, we add the following:

<ItemGroup>
    <Content Include="..\ProjectA\assets\**">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <Link>assets\%(RecursiveDir)%(Filename)%(Extension)</Link>
    </Content>
</ItemGroup>

This will effectively make a symlink of sorts to Project A's asset files (the real files), while including them in the compiled output of Project C when Project C runs, allowing them to be accessed at the path where they are expected to be.