c# - VS 代码 : How to copy files to output directory depending on build configurations

标签 c# .net visual-studio-code .net-core

我刚刚在 VS Code(C#、.NET Core)中开始了一个新项目。无论如何,我希望能够像在 visual studio 中一样将文件从我的项目目录复制到输出目录。但我也想复制特定文件,具体取决于我是为 32 位还是 64 位构建。

我环顾四周,但到目前为止,我所学会的只是复制文件,而不管我的构建配置如何。

最佳答案

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup Condition="'$(RuntimeIdentifier)' == 'win-x86'  Or '$(RuntimeIdentifier)' == 'win-x64'">
    <None Update="foo.txt">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    </ItemGroup>
  <ItemGroup Condition="'$(RuntimeIdentifier)' == 'win-x64'">
    <None Update="foo.xml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

</Project>

步骤:

  1. 通过运行 dotnet new console 创建一个控制台应用程序
  2. 将 foo.txt 和 foo.xml 添加到项目文件夹。
  3. 如上所述编辑 .csproj 文件。
  4. 使用多种配置构建项目。 dotnet build -c Release -r win-x86
  5. foo.xml 仅为 x-64 构建复制,而 foo.txtRID's 复制

Output folder

关于c# - VS 代码 : How to copy files to output directory depending on build configurations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50083611/

相关文章:

flutter - 如何使用 Flutter 在 VSCode 上修复可自动修复的问题?

visual-studio-code - Vscode 上的“源代码控制”选项卡无法工作,卡在时钟符号上,没有任何反应

c# - PsExec 打开我的远程机器进程但应用程序没有启动

c# - 窗体关闭时如何处理IE?

c# - 当它在您的机器上运行良好时,您如何确定崩溃的原因?

c# - .Net 完整配置文件配置的 Microsoft.ServiceBus.dll 问题

c# - 无法将 [] 索引应用于 IConfiguration 类型的表达式

c# - 如何反序列化使用未指定和可变属性名称的 JSON 对象

c# - 同时执行所有任务并等待它们完成?

css - 如何让 CSS IntelliSense 在 Nuxt 元素上工作?