Nuget插件不会打印任何日志

时间:2017-03-06 10:54:54

标签: c# visual-studio nuget

我创建了一个定义为Windows Runtime Component的类库,其中包含一个类:

using System;  
using System.Diagnostics;

namespace ClassLibrary1
{
    public sealed class Snaggs
    {
        public void foo()
        {
            Debug.WriteLine("Hello Snaggs");
        }        
    }    
}

我参考ClassLibrary1创建了其他项目,我称之为:

    public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;

        ClassLibrary1.Snaggs lib = new ClassLibrary1.Snaggs();
        lib.Foo();
    }

在日志中,我看到:Hello Snaggs

到目前为止一切顺利。

现在我创建了基本的nuspec

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <id>AFDemoClassLibrary</id>
        <version>999.2.4</version>
        <authors>tester</authors>
    <owners>Maxim</owners>
    <description>This is a test</description>
     <licenseUrl>http://www.snaggs.test.com</licenseUrl>
    <projectUrl>http://www.snaggs.test.com</projectUrl>
    <iconUrl>https://www.snaggs.test.com/logo.svg</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    </metadata>
    <files>
        <file src="bin\Release\**" target="lib\uap10.0" />
    </files>
</package>

我跑了:$ nuget pack AFDemoClassLibrary.nuspec

并将.nupkg个文件上传到Nuget

现在我创建了新项目并使用以下命令安装了这个库:

PM> Install-Package AFDemoClassLibrary

GOT:

Successfully installed 'AFDemoClassLibrary 999.2.4' to TestClassLibrary1

现在我再次使用以下方法调用此库:

ClassLibrary1.Snaggs lib = new ClassLibrary1.Snaggs();
lib.Foo();

但是没有得到任何输出,我没有看到Hello Snaggs

这是我得到的输出:

'TestClassLibrary1.exe' (CoreCLR: DefaultDomain): Loaded 'C:\Program Files\WindowsApps\Microsoft.NET.CoreRuntime.1.0_1.0.23819.0_x86__8wekyb3d8bbwe\mscorlib.ni.dll'. Cannot find or open the PDB file.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\entrypoint\TestClassLibrary1.exe'. Symbols loaded.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\System.Runtime.dll'. Cannot find or open the PDB file.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\WinMetadata\Windows.winmd'. Module was built without symbols.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\System.Runtime.InteropServices.WindowsRuntime.dll'. Cannot find or open the PDB file.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\ClassLibrary1.winmd'. Symbols loaded.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\System.Diagnostics.Debug.dll'. Cannot find or open the PDB file.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\System.Runtime.WindowsRuntime.dll'. Cannot find or open the PDB file.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\System.Runtime.WindowsRuntime.UI.Xaml.dll'. Cannot find or open the PDB file.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\System.Collections.dll'. Cannot find or open the PDB file.
'TestClassLibrary1.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\workspace\DEMOS\TestClassLibrary1\TestClassLibrary1\bin\x86\Debug\AppX\System.Private.Uri.dll'. Cannot find or open the PDB file.

我的问题在哪里?

也许我的环境有问题?

尝试安装此插件AFDemoClassLibrary

谢谢,

[编辑]

本地我可以打印日志。

2 个答案:

答案 0 :(得分:0)

Debug.WriteLine()仅适用于“Debug”构建(请参阅here)。使用“pack”命令时,如果没有任何选项,它将从Release版本生成一个包,没有调试符号或源文件。使用nuget pack命令中的-symbols选项生成调试包(请参阅here)。通过这种方式,您将看到日志。

答案 1 :(得分:0)

System.Diagnostics.Debug.WriteLine()方法仅适用于“调试”配置。尝试将代码更新为:

Trace.WriteLine("Hello Snaggs");