Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including a custom file in your build/publish for a .net core application

How do I include a custom file that is in the root of my project dir to be put into my build/publish folder?

If its a .json file it seems to come through automatically (probably because of .NET config being json)

I have a custom config file that is text based with a .txt extension.

I've tried:

<ItemGroup>
    <DotnetPublishFiles Include="customfile.txt"></DotnetPublishFiles>
</ItemGroup>

And

<ItemGroup>
   <Content Include="./*.txt" />
</ItemGroup>

As well as

<ItemGroup>
    <Content Include="customfile.txt" />
</ItemGroup>

Also:

<_CustomFiles Include="$(MSBuildProjectDirectory)/customfile.txt" />
    <DotNetPublishFiles Include="@(_CustomFiles)">
    </DotNetPublishFiles>
 </ItemGroup>

Nothing seems to work...

I'm using Visual Studio Code and .NET Core 3.1.

Any ideas?

like image 769
James Scott Avatar asked Oct 29 '25 09:10

James Scott


1 Answers

  <ItemGroup>
    <None Update="customfile.txt">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

JSON (as well as other suitable) files are treated the same way by SDK style projects, so for your own custom files you need to ask MSBuild explicitly.

like image 184
Lex Li Avatar answered Nov 01 '25 12:11

Lex Li



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!