如何使用具有Fakes Assembly引用的csc.exe手动编译.dll?

时间:2014-03-18 03:35:38

标签: c# microsoft-fakes csc

这是我的文件/文件夹结构:

 \
 |
 --RealLibrary\
 |  |
 |  --RealClass.cs
 |
 --SandboxFakesByHand\
    |
    --Fakes\
    |  |
    |  --RealLibrary.fakes
    |
    --Consumer.cs

RealClass.cs

的内容
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RealLibrary
{
    public class RealClass
    {
        public string Name { get; set; }
    }
}

Consumer.cs

的内容
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SandboxFakesByHand
{
    public class Consumer
    {
        public static void Method()
        {
            var a = new RealLibrary.Fakes.ShimRealClass();
        }
    }
}

RealLibrary.fakes

的内容
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="RealLibrary"/>
</Fakes>

以下是我从VS2012(Premium)的开发人员命令提示符(从\RealLibrary\开始)尝试的内容:

> csc /target:library RealClass.cs
> cd ..\SandboxFakesByHand
> csc /target:library Consumer.cs

最后一个给我一个错误:

Microsoft (R) Visual C# Compiler version 4.0.30319.33440
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.

Consumer.cs(13,25): error CS0246: The type or namespace name 'RealLibrary' could
        not be found (are you missing a using directive or an assembly
        reference?)

手动编译Consume.cs文件需要做什么?

1 个答案:

答案 0 :(得分:1)

您需要添加对csc行的引用:

csc /target:library /reference:..\RealLibrary\RealClass.dll Consumer.cs