Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding C# sources in PDB with new csproj

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.

like image 566
Shay Rojansky Avatar asked Mar 10 '17 09:03

Shay Rojansky


People also ask

What is embedded C used for?

Embedded C is generally used to develop microcontroller-based applications. C is a high-level programming language. Embedded C is just the extension variant of the C language. This programming language is hardware independent.

What is embedded C example?

Embedded C programming plays a key role in performing specific function by the processor. In day-to-day life we used many electronic devices such as mobile phone, washing machine, digital camera, etc. These all device working is based on microcontroller that are programmed by embedded C.

Is embedded C still used?

It is the most popular language for embedded systems developers and is used in nearly 80% of all embedded projects.

Is embedded C a good career?

Yes, embedded software engineering is a good career which offers a high salary.


2 Answers

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.

like image 144
Lukáš Lánský Avatar answered Oct 06 '22 16:10

Lukáš Lánský


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.

like image 23
m0sa Avatar answered Oct 06 '22 17:10

m0sa