Search code examples
.net-corecsprojdotnet-cli

How to add EmbeddedResource to project with dotnet CLI?


I've got some resources that need to be embedded in the DLL. If I use Visual Studio I can add them using the UI. This will add the following to the csproj file:

<EmbeddedResource Include="Mocks\MyMock.GetDimensions().json" />

No I like to add the resource with a dotnet command from the terminal. How would I go about?

I'm (re)generating some files in PowerShell and I need to embed these files in the DLL so it can be accessed by my code.


Solution

  • There is no built-in verb in the CLI that handles this. This would have to be done by a 3rd party CLI command line tool installed into the project (also by editing the csproj file) or a 3rd party global tool (support for global tools is coming in the 2.2.0 CLI).

    For your specific use case, adding all json files through a wildcard is the easiest option to include all generated content:

    <ItemGroup>
      <EmbeddedResource Include="Mocks\**\*.json" />
    </ItemGroup>