VS代码:如何根据构建配置将文件复制到输出目录 [英] VS Code: How to copy files to output directory depending on build configurations
本文介绍了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:
- 通过运行
dotnet new console
创建控制台应用
- 将foo.txt和foo.xml添加到项目文件夹中.
- 按上述编辑
.csproj
文件. - 使用多种配置构建项目.
dotnet build -c Release -r win-x86
仅复制 -
foo.xml
用于x-64
构建,而复制foo.txt
则同时复制
- Create a console app by running
dotnet new console
- Add foo.txt and foo.xml to the project folder.
- Edit the
.csproj
file as above. - Build the project with multiple configurations.
dotnet build -c Release -r win-x86
foo.xml
is copied only for ax-64
build whereasfoo.txt
is copied for both RID's
这篇关于VS代码:如何根据构建配置将文件复制到输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文