You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Stryker.NET测试执行目录?解决依赖文件找不到异常

Stryker.NET 找不到依赖文件的解决方法

问题描述

我在使用Stryker.NET时遇到了System.IO.FileNotFoundException异常,原因是部分依赖文件存储在另一个目录(我的输出文件也复制到该目录),Stryker.NET无法找到这些文件。请问如何修改Stryker.NET的测试执行目录?

异常信息

未处理的异常。System.IO.FileNotFoundException: 找不到文件'some.dll'。
文件名: 'some.dll'
   在 Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   在 Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   在 System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
   在 System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
   在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   在 Roslyn.Utilities.StandardFileSystem.OpenFile(String filePath, FileMode mode, FileAccess access, FileShare share)
   在 Roslyn.Utilities.CommonCompilerFileSystemExtensions.OpenFileWithNormalizedException(ICommonCompilerFileSystem fileSystem, String filePath, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
   在 Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation)
   在 Stryker.Core.Initialisation.Buildalyzer.IAnalyzerResultExtensions.LoadReferences(IAnalyzerResult analyzerResult)+MoveNext() 位置 /_/src/Stryker.Core/Stryker.Core/Initialisation/Buildalyzer/IAnalyzerResultExtensions.cs:行号 98
   在 System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   在 System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   在 System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
   在 Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
   在 Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
   在 Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(String assemblyName, CSharpCompilationOptions options, IEnumerable`1 syntaxTrees, IEnumerable`1 references, CSharpCompilation previousSubmission, Type returnType, Type hostObjectType, Boolean isSubmission)
   在 Microsoft.CodeAnalysis.CSharp.CSharpCompilation.Create(String assemblyName, IEnumerable`1 syntaxTrees, IEnumerable`1 references, CSharpCompilationOptions options)
   在 Stryker.Core.Compiling.CsharpCompilingProcess.GetCSharpCompilation(IEnumerable`1 syntaxTrees) 位置 /_/src/Stryker.Core/Stryker.Core/Compiling/CsharpCompilingProcess.cs:行号 138
   在 Stryker.Core.Compiling.CsharpCompilingProcess.GetSemanticModels(IEnumerable`1 syntaxTrees) 位置 /_/src/Stryker.Core/Stryker.Core/Compiling/CsharpCompilingProcess.cs:行号 102
   在 Stryker.Core.MutationTest.CsharpMutationProcess.Mutate(MutationTestInput input) 位置 /_/src/Stryker.Core/Stryker.Core/MutationTest/CsharpMutationProcess.cs:行号 59
   在 Stryker.Core.MutationTest.MutationTestProcess.Mutate() 位置 /_/src/Stryker.Core/Stryker.Core/MutationTest/MutationTestProcess.cs:行号 88
   在 Stryker.Core.Initialisation.ProjectMutator.MutateProject(StrykerOptions options, MutationTestInput input, IReporter reporters) 位置 /_/src/Stryker.Core/Stryker.Core/Initialisation/ProjectMutator.cs:行号 38
   在 Stryker.Core.Initialisation.ProjectOrchestrator.MutateProjects(StrykerOptions options, IReporter reporters, ITestRunner runner)+MoveNext() 位置 /_/src/Stryker.Core/Stryker.Core/Initialisation/ProjectOrchestrator.cs:行号 68
   在 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   在 Stryker.Core.StrykerRunner.RunMutationTest(IStrykerInputs inputs, ILoggerFactory loggerFactory, IProjectOrchestrator projectOrchestrator) 位置 /_/src/Stryker.Core/Stryker.Core/StrykerRunner.cs:行号 61
   在 Stryker.CLI.StrykerCli.RunStryker(IStrykerInputs inputs) 位置 /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:行号 102
   在 Stryker.CLI.StrykerCli.<>c__DisplayClass11_0.<Run>b__0() 位置 /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:行号 74
   在 McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass143_0.<OnExecute>b__0(CancellationToken _)
   在 McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   在 McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   在 Stryker.CLI.StrykerCli.Run(String[] args) 位置 /_/src/Stryker.CLI/Stryker.CLI/StrykerCLI.cs:行号 80
   在 Stryker.CLI.Program.Main(String[] args) 位置 /_/src/Stryker.CLI/Stryker.CLI/Program.cs:行号 14

解决方法

1. 命令行指定工作目录

运行Stryker.NET时,通过--working-directory参数指定依赖文件所在的目录:

dotnet stryker --working-directory "你的依赖目录路径"

2. 配置文件设置工作目录

在项目根目录创建或修改stryker-config.json,添加workingDirectory配置项:

{
  "stryker-config": {
    "workingDirectory": "你的依赖目录路径"
  }
}

3. 调整测试项目输出路径

修改测试项目的.csproj文件,将输出目录设置为依赖文件所在目录,让Stryker默认在此目录查找文件:

<PropertyGroup>
  <OutputPath>你的依赖目录路径</OutputPath>
</PropertyGroup>

4. 添加依赖目录到程序集搜索路径

在测试项目中添加程序集元数据,指定额外的探测路径:

using System.Reflection;

[Assembly: AssemblyMetadata("AdditionalProbingPaths", "你的依赖目录路径")]

内容的提问来源于stack exchange,提问作者Felix Arnold

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 18:08:12