首页 > 解决方案 > Azure Devops VS 测试失败系统找不到指定的文件。警告:程序集绑定日志记录已关闭

问题描述

我的单元测试在本地成功运行,但是当我通过管道中的 VSTest 步骤运行它时,出现以下故障。

抛出异常。System.IO.FileNotFoundException:System.IO.FileNotFoundException:无法加载文件或程序集“AutoFixture,版本=4.14.0.0,Culture=neutral,PublicKeyToken=b24654c590009d4f”或其依赖项之一。系统找不到指定的文件。警告:程序集绑定日志记录已关闭

抛出异常。System.IO.FileNotFoundException:System.IO.FileNotFoundException:无法加载文件或程序集“PriceListManagement.Integration,版本=1.0.0.0,文化=中性,PublicKeyToken=null”或其依赖项之一。系统找不到指定的文件。警告:程序集绑定日志记录已关闭。

(PriceListManagement.Integration 是一个 .Net 框架项目)

有想法该怎么解决这个吗?下面是管道 Yaml

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
     **\*UnitTests*.dll
     **\*.IntegrationTests*.dll

标签: c#.netazure-devops

解决方案


无法加载文件或程序集“AutoFixture,版本=4.14.0.0,Culture=neutral,PublicKeyToken=b24654c590009d4f”或其依赖项之一。该系统找不到指定的文件。

此问题可能与xxx.csproj文件中指定的项目依赖项有关。

您可以检查是否引用了有问题的 .dll 文件 (AutoFixture,PriceListManagement.Integration)。

例如:

  <ItemGroup>
    <Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\MSTest.TestFramework.2.1.2\lib\net48\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
    </Reference>
  </ItemGroup>

如果是,则需要检查HintPath 是否包含目标文件。

对于自动夹具:

可以在package.config文件中指定对应的包

包.config

<packages>
  <package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net472" />
  <package id="MSTest.TestFramework" version="1.3.2" targetFramework="net472" />
  <package id="AutoFixture" version="4.14.0" targetFramework="net452" />
</packages>

.csproj 文件提示路径:

<HintPath>..\packages\AutoFixture.4.14.0\lib\net452\AutoFixture.dll</HintPath>

对于 PriceListManagement.Integration

由于是项目依赖,所以需要判断生成的.dll是否在对应的路径中。

另一方面,根据您的 yaml 模板,这似乎是一个标准的构建过程。它可以成功运行。


推荐阅读