首页 > 解决方案 > 如何填充 System.Environment?

问题描述

我正在尝试填充 System.Environment:

Dim args = {"a", "b", "c", "d", "e")}
System.Fakes.ShimEnvironment.GetCommandLineArgsGet =
Function() As String()
   Return args
End Function

我参考了 C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\PublicAssemblies\Microsoft.QualityTools.Testing.Fakes.dll

我的项目的 Fakes 文件夹中有以下文件:

mscorlib.fakes:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="mscorlib" Version="4.0.0.0"/>
</Fakes>

系统假货:

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="System" Version="4.0.0.0"/>
</Fakes>

但是我得到编译错误:

错误 BC30456:“ShimEnvironment”不是“System.Fakes”的成员。

如何填充 System.Environment?

标签: .net-4.5visual-studio-2019shim

解决方案


正如https://social.msdn.microsoft.com/Forums/vstudio/en-US/b49e9f5d-0e57-46b1-8ced-f3231db5e813/cannot-find-a-shim-for-systemenvironmentmachinename-etc?forum=vsunittest中的建议我必须将以下内容放入 mscorlib.fakes:

  <ShimGeneration>
    <Add FullName="System.Environment"/>
  </ShimGeneration>

推荐阅读