如何使用具有假程序集引用的csc.exe手动编译.dll
本文关键字:exe csc dll 编译 引用 何使用 程序集 | 更新日期: 2023-09-27 17:50:39
我的文件/文件夹结构如下:
'
|
--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?)
我需要做什么来手工编译consumer .cs文件?
您需要向csc
行添加引用:
csc /target:library /reference:..'RealLibrary'RealClass.dll Consumer.cs