我刚刚在 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>
步骤:
- 通过运行
dotnet new console
创建一个控制台应用程序 - 将 foo.txt 和 foo.xml 添加到项目文件夹。
- 如上所述编辑
.csproj
文件。 - 使用多种配置构建项目。
dotnet build -c Release -r win-x86
foo.xml
仅为x-64
构建复制,而foo.txt
为 RID's 复制
关于c# - VS 代码 : How to copy files to output directory depending on build configurations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50083611/