小编Cod*_*Fox的帖子

NUnit可以期待超时吗?

我想测试一种我希望在特定情况下阻止的方法.

我尝试了TimeoutAttribute和的组合ExpectedExceptionAttribute:

[Test]
[Timeout(50), ExpectedException(typeof(ThreadAbortException))]
public void BlockingCallShouldBlock()
{
    this.SomeBlockingCall();
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不起作用,因为ThreadAbortException我在这里读到似乎被NUnit本身抓住了.

有没有办法期待超时(使用NUnit)?

c# nunit timeout nunit-2.5

7
推荐指数
1
解决办法
581
查看次数

AggregateException中的TaskCanceledException不包含堆栈跟踪

我正在使用任务并行库来运行一个任务 - 当取消时 - 抛出OperationCanceledException,然后使用AggregateException捕获它,如下所示.AggregateException包含TaskCanceledExceptions列表,它对应于抛出的异常.不幸的是,这些TaskCanceledExceptions似乎正在丢失原始异常抛出的堆栈跟踪.这是设计的吗?

try
{
    task1.Wait();
}
catch (AggregateException aggEx)
{
    var tcex = ex as TaskCanceledException;
    if (tcex != null)
    {
        Debug.WriteLine("InnerException:{0}, Message:{1}, Source:{2}, StackTrace: {3}",
            tcex.InnerException, tcex.Message, tcex.Source, tcex.StackTrace);

        return true;
    }
    else
    {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

结果:

InnerException:, Message:A task was canceled., Source:, StackTrace: 
Run Code Online (Sandbox Code Playgroud)

c# .net-4.0 task-parallel-library cancellation aggregateexception

6
推荐指数
1
解决办法
2371
查看次数

如何使用 NuGet 包部署 T4 包含文件

我有一些 T4 包含文件,我想在多个项目中重用它们。因此,我创建了一个 NuGet 包并将文件放置在该包的 Tools 文件夹中。现在它们已安装在该packages\PackageName.x.x.x\Tools文件夹中,我可以在项目的 T4 文件中添加包含指令。

但这样做的缺点是,路径中的版本号会在我创建包的新版本时发生变化。这将需要我更新项目中的所有包含指令。

有人知道对此有什么好的方法吗?

.net t4 nuget

5
推荐指数
1
解决办法
2368
查看次数

无法将自定义 dotnet 命令作为 TeamCity 构建步骤运行

当前设置:

  • 运行 Ubuntu 18 的服务器
  • TeamCity Professional 2019.2(内部版本 71499)

我正在使用以下命令设置构建任务以生成 SQL 迁移脚本:

dotnet ef migrations script --output "script.sql" --context MyContext
Run Code Online (Sandbox Code Playgroud)

但是,在 TeamCity 上运行构建时,构建失败并显示以下错误:

Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET Core program, but dotnet-ef does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found …
Run Code Online (Sandbox Code Playgroud)

.net teamcity entity-framework-migrations

5
推荐指数
1
解决办法
293
查看次数

为什么读取设置属性值会使SettingsPropertyValue对象变脏?

在实现自定义设置提供程序时,我注意到访问设置属性的值会将其IsDirty标志更改为true.

// Arrange
var property = new SettingsProperty("property1")
{
    PropertyType = typeof(Color),
    DefaultValue = "Green"
};

// Act
var result = new SettingsPropertyValue(property);

// Assert
Assert.That(result.IsDirty, Is.False);
Assert.That(result.PropertyValue, Is.EqualTo(Color.Green));
Assert.That(result.IsDirty, Is.False); // <-- Assertion fails
Run Code Online (Sandbox Code Playgroud)

Reflector给出了一个问题的答案,为什么PropertyValuegetter的行为是这样的 - 它包含如下语句:

if (_Value != null && !Property.PropertyType.IsPrimitive && !(_Value is string) && !(_Value is DateTime))
{
    _UsingDefaultValue = false;
    _ChangedSinceLastSerialized = true;
    _IsDirty = true;
}
Run Code Online (Sandbox Code Playgroud)

乍一看奇怪的行为可以让任何人对此有所了解吗?

c# settingsprovider

3
推荐指数
1
解决办法
458
查看次数

为VSPackage加载解决方案时如何通知?

当解决方案已完全加载时,我想收到通知。受此答案启发,我尝试实施IVsSolutionEvents

当我加载具有两个C#项目的解决方案时,请等到加载完成并最终关闭Visual Studio 2017时,输出仅显示以下跟踪消息:

VSTestPackage1: OnAfterOpenProject
VSTestPackage1: OnQueryCloseSolution
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnBeforeCloseSolution
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnBeforeCloseProject
VSTestPackage1: OnQueryCloseProject
VSTestPackage1: OnBeforeCloseProject
VSTestPackage1: OnAfterCloseSolution
Run Code Online (Sandbox Code Playgroud)

这是预期的行为吗?为什么OnAfterOpenSolution不被调用?

这是程序包的实现:

[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[Guid(PackageGuidString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly",
    Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
[ProvideAutoLoad(VSConstants.UICONTEXT.SolutionHasMultipleProjects_string)]
public sealed class VSPackage1 : Package, IVsSolutionEvents
{
    public const string PackageGuidString = "2e655097-9510-4cf8-b9d4-ceeacebbaf3c";

    private DTE _dte;
    private uint _hSolutionEvents = uint.MaxValue;
    private IVsSolution _solution; …
Run Code Online (Sandbox Code Playgroud)

c# vspackage vsix

2
推荐指数
1
解决办法
935
查看次数