Embedding C# sources in PDB with new csproj

耗尽温柔 提交于 2019-12-01 06:06:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!