首页 > 解决方案 > 由 Azure Devops Server 代理运行时单元测试找不到文件

问题描述

app.config文件中有对另一个配置文件的引用。

<system.web>
    <roleManager configSource="Roles.config"/>

当从 Visual Studio 执行测试用例时,一切正常。但是,如果它由自托管代理从 Azure Devops Server 运行,则会引发以下异常:

System.Configuration.ConfigurationErrorsException: Unable to open configSource file 'Roles.config'.

该文件始终复制到 bin 目录。

有任何想法吗?

Roles.config更新:经过一番调查,发现临时工作文件夹中没有文件:agent\_work\2\s\TestResults\Deploy_srv 2020-05-15 14_46_18\Out\

YAML 的一小部分

- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\One.dll
     **\$(BuildConfiguration)\Two.dll

标签: azure-devops

解决方案


有任何想法吗?

也许您可以查看以下提示以进行故障排除:

1.首先你应该确保Roles.config文件在版本控制之下。

2.然后确保此文件的复制选项设置为始终复制,检查您的项目文件(xx.xxproj)并检查它是否存在:

<xxx Include="Roles.config">
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</xxx>

3.由于该configSource属性使用相对路径,因此您应确保该Roles.config文件与您的 app.config 文件位于同一目录下。


推荐阅读