简体   繁体   English

如何使用 Visual Studio Code 在 dotnet 构建中包含资源文件

[英]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.

相关问题 使用 Visual Studio Code 在构建时复制内容文件 - Copying Content files on build with Visual Studio Code Visual Studio Code:如何配置“dotnet”在编译时不显示警告 - Visual Studio Code: How to configure 'dotnet' not to show warnings when compiling Dotnet手表与调试Visual Studio代码 - Dotnet watch with debug Visual Studio Code Visual Studio Code Do.net Core C# 错误:“找不到类型或命名空间名称‘System’”,但构建成功 - Error in Visual Studio Code Dotnet Core C#: "The type or namespace name 'System' could not be found", but build succeeds Visual Studio 扩展资源文件 - Visual studio extension resource files 如何在不依赖Visual Studio C#的生成中包含项目 - How to include a project in a build that is not a dependency in Visual Studio c# 如何在Visual Studio的发布配置文件中包含动态生成的文件 - How to include dynamically generated files in Visual Studio's publish profile 如何在Visual Studio项目中包含网络网站源文件 - how to include net web site source files in Visual Studio project 如何在 Visual Studio、C# 项目的部署中包含文件和文件夹? - How to include files and folders in the deployment of a visual studio, C# project? 更改目标版本时 Visual Studio 2017 dotnet 崩溃 - Visual Studio 2017 dotnet crash when changing target build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM