如何强制dll在运行时可访问

问题描述

在以下代码中,由于.cs文件中没有使用LINQ扩展方法,因此不会从编译中输出System.Core.dll:

using System.Collections.Generic;
using System.Linq;

namespace LinqTestFramework
{
    class Program
    {
        static void Main(string[] args)
        {
            var dict = new Dictionary<int,string>()
            {
                { 1,"David" }
            };
        }
    }
}

但是,在调试期间,我希望能够在dict对象上调用LINQ扩展方法,并在“监视”窗口中查看结果。

如何在编译后强制包含System.Core.dll,以便在调试期间可以访问LINQ扩展方法

更新

我尝试过包含确实使用LINQ的代码。我发现这在编译输出中确实包含System.Core.dll,但是代码在运行时仍然不可用:

enter image description here

为了能够在“监视”窗口的调试过程中使用Linq扩展方法,我必须取消引用使用Linq的代码的行的注释。

在调试期间是否有任何方法可以访问Linq扩展方法,而不必引用使用Linq扩展方法代码

解决方法

添加确实使用Linq的方法。不必由您的代码实际调用,只需引用即可。

,

当要显式引用程序集时,我使用此扩展名:

public static class AssemblyReference
{
    /// <summary>
    /// Installs reference to assembly in which specified type resides.
    /// It will be copied on build even in release mode.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static void Install<T>()
    {

    }
}

然后,您可以使用程序集加载。当然,最简单的方法就是从名称空间中调用某些东西。