简体   繁体   中英

How to include Resource files in dotnet build with Visual Studio Code

I'm building a WPF application with dotnet core in the visual studio code editor. The problem I'm having is that the Resources folder isn't included with builds, or so it seems. I can't find an example of how to to do that outside of Visual Studio and any image I try to use doesn't work. Any tips or examples would be appreciated!

Folder structure

|- Root Folder
   |- bin
      |- Debug
         |- netcoreapp3.1
            |- [this has dlls and exe, but no Resources]
   |- obj
   |- Data
   |- Pages
   |- Resources
      |- images

Commands to run app:

dotnet clean
dotnet build
dotnet run

It's all standard stuff so please point out any missing commands, misplaced files, etc. I'm new to WPF and trying to build windows app in VS Code.

Just add your resource file manually to .csproj file if you want to use it as embedded resource:

<EmbeddedResource Include="Resources\images\icon.ico" />

or if you want to copy files to your build folder

<ItemGroup>
   <Content Include="Resources\*.*">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
   </Content>
</ItemGroup>  

In your .csproj add

<ItemGroup>
  <Content Include="Resources\Images\New Bitmap Image.bmp">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>
</ItemGroup>

Directory structure post build:

\bin\Debug\netcoreapp2.1\Resources\Images

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM