问题
The recently-released .NET tooling seem to have support for embedding C# in PDBs, which should improve the experience of stepping into third-party, etc. Running csc /?
, I can clearly see the /embed option: "Embed all source files in the PDB."
However, there doesn't seem to be any way to specify this in csproj. What's more, there doesn't seem to be any provisions for passing arbitrary switches to the compiler, which I would use to manually pass /embed.
Can anyone confirm that I haven't missed anything and that build support for /embed is currently lacking? Is there an issue for this (and if not where would it go)? Any suggested workaround would be appreciated too.
回答1:
There's now a proper MSBuild EmbedAllSources property:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<EmbedAllSources>true</EmbedAllSources>
[...]
From what I observed locally, it behaves the same as the mentioned EmbedFiles
target.
回答2:
Looks like the roslyn task should support them via the EmbeddedFiles Item Group, by adding this to your .csproj:
<Target Name="EmbedSources" BeforeTargets="CoreCompile">
<ItemGroup>
<EmbeddedFiles Include="@(Compile) " />
</ItemGroup>
</Target>
... which is basically what the /embed option does.
You probably need to also provide a SourceLink json file, to wire up the sources in the PDB, not sure that happens automatically.
来源:https://stackoverflow.com/questions/42714352/embedding-c-sharp-sources-in-pdb-with-new-csproj