[英]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.我正在 Visual Studio 代码编辑器中构建一个带有 dotnet 核心的 WPF 应用程序。 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.我找不到如何在 Visual Studio 之外执行此操作的示例,并且我尝试使用的任何图像都不起作用。 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.这都是标准的东西,所以请指出任何丢失的命令、错位的文件等。我是 WPF 的新手,并试图在 VS Code 中构建 Windows 应用程序。
Just add your resource file manually to .csproj file if you want to use it as embedded resource:如果您想将其用作嵌入式资源,只需将您的资源文件手动添加到 .csproj 文件中:
<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在您的 .csproj 添加
<ItemGroup>
<Content Include="Resources\Images\New Bitmap Image.bmp">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
Directory structure post build:构建后的目录结构:
\bin\Debug\netcoreapp2.1\Resources\Images
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.