As a temporary solution (until we get an internal Symbol server setup), I am trying to build Nuget packages that include all source code for the DLL so that our users can debug its code.
I have build the following Nuspec file
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>My Assembly</id>
<version>1.0.0</version>
<title>My Assembly</title>
<authors>Me</authors>
<owners>Me</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>My description</description>
<copyright>© Me 2014</copyright>
<dependencies>
<dependency id="Autofac" />
<dependency id="Autofac.Configuration" />
<dependency id="Autofac.Web"/>
<dependency id="AutoMapper" />
<dependency id="FluentNHibernate" />
<dependency id="Iesi.Collections"/>
<dependency id="Newtonsoft.Json" />
<dependency id="NHibernate"/>
</dependencies>
<frameworkAssemblies>
<frameworkAssembly assemblyName="System.Web" />
</frameworkAssemblies>
</metadata>
<files>
<file src="bin\MyAssembly.dll" target="lib" />
<file src="bin\MyAssembly.pdb" target="lib" />
<file src="**\*.cs" target="src"/>
</files>
</package>
When I add build this Nuspec file I end up with a nice package including my DLL, plus a folder called src containing the source code.
What I can't see how to do is to get Visual Studio to use the .cs files in the src directory when debugging by referenced DLL (all I currently get is a dissembled preview). Is this possibly, I assume it should be, however I can't find any examples of how to do this.
Edit: Thanks for the accepted answer. Just to note, the other way I found of doing this is to add the 'src' folder for the Nuget package in the consuming solutions Common Properties -> Debug Source Files list.
While you are running your program, you can bring up the Debug|Modules window. From there, you can select the DLL and browse for the corresponding PDB file. After that, you can manually open the source CS file and set breakpoints in it. Visual Studio will verify if the PDB and CS correspond to the compiled CS file, but that should be alright since you package them together.
来源:https://stackoverflow.com/questions/26972844/how-to-debug-using-nuget-source-code