【发布时间】:2016-10-05 23:38:43
【问题描述】:
我想知道在使用 .NET Core 工具构建新的控制台应用程序并且仅针对 .NET 4.5.1 框架时,如何引用本地未签名的 CLR 4.0 程序集。
我在 Windows 10 机器上做了以下操作:
- 使用以下代码创建一个新的 MyLibrary.cs:
using System;
namespace MyNamespace
{
public class MyLibrary
{
public static void SayHi()
{
Console.WriteLine("Hi");
}
}
}
用
csc /t:library MyLibrary.cs编译以上代码。创建一个新文件夹和一个 .NET Core 项目。
mkdir MyConsoleApp
cd MyConsoleApp
dotnet new
- 编辑自动生成的 project.json 文件以面向 .NET 4.5.1。
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"net451" : { }
}
}
- 测试项目是否构建和运行。确实如此。
dotnet restore
dotnet build
bin\Debug\net451\MyConsoleApp.exe
- 编辑 Program.cs 以调用 MyLibrary.dll 中的代码。
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
MyNamespace.MyLibrary.SayHi();
}
这就是我卡住的地方。
我应该在哪里放置我的 DLL 以及在 project.json 中放置什么,以便我可以在我的程序集中调用代码?
【问题讨论】:
-
不确定,但你必须制作一个 nuget 包吗?有什么想法吗?
标签: .net-core