0

I want to create a NuGet package from a class library targeting .Net Framework 4.5 (not 4.5.1, or 4.5.2) which contains source code files, and I have trouble finding how.

The reason being that I would like to be able to debug it. I already created the symbols package, and it seems to works, provided I open the *.cs file I want to debug when VS2022 asks me for it.

To pack, I use a standard nuspec file, to which I specified the files I want to add taking inspiration from here

  <contentFiles>
    <files include="**\*.cs" buildAction="content" flatten="true" copyToOutput="true"/>
  </contentFiles>
</metadata>
<files>
  <file src="**\*.cs" target="src" />
</files>

All the files are sent to the .nupkg in a src folder, as expected.

The command I use to pack is

nuget pack *.csproj -Symbols -SymbolPackageFormat snupkg

I spent all day trying to figure out how to include source so that VS can find the source files after I install the package, to no avail. Any feedback would be appreciated.

Is there a way for this to be streamlined, or is uploading the file you want to debug the only option for 4.5?

Thanks!

Ileana Profeanu
  • 377
  • 2
  • 10
  • 33
  • I'm confused when you talk about symbols here. If you are packing `.cs` files in the NuGet package, surely you want those files to be added to whatever target project references the package. Since the files are added to the target project, they participate in the target project's build process, and should be "debuggable" in that context: the symbol generated during the project compilation will have all the required information about those files. It makes no sense to rely on a symbols package in this case. Please let me know if I'm missing something. – julealgon Nov 11 '22 at 16:58
  • I want the files to be available in the project I install the NuGet package into. The issue is that they aren't available there. VS says it cannot find them. This is what the question is about, why aren't they found. – Ileana Profeanu Nov 11 '22 at 17:07
  • @julealgon "since the files are added to the target project" they are added because I upload them manually when VS prompts me for them. I want the end user to be able to debug the package - this means having both the symbols and the sources available without the user having to upload the source files into VS when prompted. i.e. exactly what happens when I pack a .net framework 4.7 package using "dotnet pack". only in the case described in my question, this does not happen – Ileana Profeanu Nov 11 '22 at 17:10
  • I'm still confused.... are you adding these `.cs` files _in addition to a dll that was compiled with them_ in the package? Or does the package _only contain `.cs` files_? If it's the former, I've never seen that done for the purposes of debugging and would suggest looking into [SourceLink](https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/sourcelink) instead. If it's the latter, then I can't help you. – julealgon Nov 11 '22 at 19:26
  • The question is actually if there is a way of packing a .net framework class library with symbols so the package is able to be stepped into/debuged from VS without having to provide the source files manually – Ileana Profeanu Nov 12 '22 at 21:49
  • Please look at the link I provided. SourceLink provides exactly what you are looking for and is the newest and most recommended approach of doing it. – julealgon Nov 14 '22 at 12:02

1 Answers1

0

As we can see that contentFiles is used for PackageReference form this link.

And .NET Framework projects support PackageReference, but currently default to packages.config.

I'm not sure which format your project is using. If you are using package.config you can try to Migrate from packages.config to PackageReference and try again.

Jingmiao Xu-MSFT
  • 2,076
  • 1
  • 3
  • 10