Copy file to build directory

How would I make it so a file I added to the program files would get copied to the build directory when the program is built?
11 Replies
Angius
Angius4mo ago
In VS, right-click the file, open properties, set it to copy always or copy if newer
Protogen Posting
Protogen PostingOP4mo ago
I'm in vs code there's no properties thingy
Angius
Angius4mo ago
Open the .csproj file then and add
<ItemGroup>
<Content Update="myfile.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Update="myfile.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
Protogen Posting
Protogen PostingOP4mo ago
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Content Update="testingprogram.ASS">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>ASS_Compiler</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Content Update="testingprogram.ASS">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>ASS_Compiler</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
it doesn't seem to be copying it
No description
Angius
Angius4mo ago
It's not in bin/Debug/net8.0? Try
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ <CopyToPublishDirectory>Always</CopyToPublishDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ <CopyToPublishDirectory>Always</CopyToPublishDirectory>
Protogen Posting
Protogen PostingOP4mo ago
still no I'm also on linux if that's any help
Angius
Angius4mo ago
Shouldn't make a difference
Protogen Posting
Protogen PostingOP4mo ago
weird
Angius
Angius4mo ago
Uh,
<ItemGroup>
<None Update="foo.txt" CopyToOutputDirectory="Always" />
</ItemGroup>
<ItemGroup>
<None Update="foo.txt" CopyToOutputDirectory="Always" />
</ItemGroup>
? Or Content instead of None
Protogen Posting
Protogen PostingOP4mo ago
ok that worked thanks!!!
Angius
Angius4mo ago
Cool

Did you find this page helpful?