【问题标题】:VS Code: How to copy files to output directory depending on build configurationsVS Code:如何根据构建配置将文件复制到输出目录
【发布时间】:2018-04-29 05:16:22
【问题描述】:

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

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

【问题讨论】:

  • 右键单击您的解决方案 ==> 属性 ==> 构建 ==> 平台目标,您会知道的
  • @ZohirSalakCeNa 我没有使用 Visual Studio。
  • 你试过这篇文章了吗? stackoverflow.com/questions/44374074/…
  • @Daniel 这是我找到的第一篇文章,但它并没有告诉我如何处理不同的架构。
  • 尝试File.Copy(sourcePath, C:\File.txt); 并获取您的项目目录,使用Environment.CurrentDirectory

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


【解决方案1】:
<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.txt 仅针对 RID's 进行复制

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-27
    • 2019-12-23
    • 2013-04-08
    • 1970-01-01
    • 2016-01-12
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多