c# - 如何在 .NET Core 中传递预处理器条件
问题描述
我有一些使用条件编译的测试代码,如下所示:
public class MyFixture : IDisposable
{
public MyFixture()
{
#if UseMySqlForTesting
... do A
#else
... do B
#endif
}
UseMySqlForTesting
如果为真,还有一些相关文件:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<UseMySqlForTesting>true</UseMySqlForTesting>
</PropertyGroup>
...
<!-- copy the files if we use mysql, otherwise, don't copy them -->
<ItemGroup Condition="$(UseMySqlForTesting)">
<None Update="MySql.Test.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="other.configuration.files.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
现在我想dotnet test
用来测试项目。
问题:
有没有这样的方法:
dotnet test /p:UseMySqlForTesting=false
dotnet test /p:UseMySqlForTesting=true
它可以通过它自动测试#if
or#else
分支并在需要时复制相关文件?
解决方案
推荐阅读
- google-apps-script - 谷歌 appscript 将工作表转换为 PDF
- javascript - 如何使用排序表达式对对象属性进行动态排序?
- perl - 如何使用 perl 和 sendmail 从 URL 发送 pdf [Mail::Sendmail]
- r - 如何删除文件夹中多个 csv 文件中的某些列?
- azure - Azure API 开发人员门户 - Okta 集成
- c++ - Mingw 或 msvc 中的 std::filesystem::relative 错误?
- arrays - Set initial active element, after resizing array of elements
- string - Get a specific octet from the string representation of an IPv4 address
- javascript - 将项目导入 React 后不再播放声音
- angular - 一旦我尝试更改 ng-template (Angular) 上的值,NgbPopover 就会关闭