VS代码:如何根据构建配置将文件复制到输出目录

Mat*_*yer 2 .net c# .net-core visual-studio-code

我刚刚在VS Code(C#,.NET Core)中启动了一个新项目.无论如何,我希望能够将我的项目目录中的文件复制到输出目录,就像我在visual studio中一样.但我也想根据我是否构建32位或64位来复制特定文件.

我环顾四周,但到目前为止,我已经学会了如何复制文件,无论我的构建配置如何.

小智 7

<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>
Run Code Online (Sandbox Code Playgroud)

脚步:

  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.txt复制,而为两个RID复制

导出目录