VS代码:如何根据构建配置将文件复制到输出目录 [英] VS Code: How to copy files to output directory depending on build configurations

查看:225
本文介绍了VS代码:如何根据构建配置将文件复制到输出目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I just started a new project in VS Code (C#, .NET Core). Anyways, I want to be able to copy files from within my project directory to the output directory like I can in visual studio. But I also want to copy specific files depending on whether or not I'm building for 32 or 64 bit.

我环顾四周,但是到目前为止,我学到的所有方法都是复制文件,而不管我的构建配置如何.

I've looked around but so far all I've learnt how to do is copy files regardless of my build configurations.

推荐答案

<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>


步骤:


Steps:

  1. 通过运行dotnet new console
  2. 创建控制台应用
  3. 将foo.txt和foo.xml添加到项目文件夹中.
  4. 按上述编辑.csproj文件.
  5. 使用多种配置构建项目. dotnet build -c Release -r win-x86
  6. 仅复制
  7. foo.xml用于x-64构建,而复制foo.txt则同时复制
  1. Create a console app by running dotnet new console
  2. Add foo.txt and foo.xml to the project folder.
  3. Edit the .csproj file as above.
  4. Build the project with multiple configurations. dotnet build -c Release -r win-x86
  5. foo.xml is copied only for a x-64 build whereas foo.txt is copied for both RID's

这篇关于VS代码:如何根据构建配置将文件复制到输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆