Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

How can I make this work with embedded source files? #192

Closed
shaynevanasperen opened this issue Apr 6, 2017 · 14 comments
Closed

How can I make this work with embedded source files? #192

shaynevanasperen opened this issue Apr 6, 2017 · 14 comments

Comments

@shaynevanasperen
Copy link

I want to be able to create a library that has an embedded PDB as well as embedded source files and have the SourceLink file be generated so that it points to the files that are embedded in the dll of the library rather than a URL. I can't figure out how to do this. Please update your documentation to make it more clear.

@ctaggart
Copy link
Owner

ctaggart commented Apr 8, 2017

If you are embedding all the source files, you do not need to enable source linking. You do not need this tool. I tried to explain this in the overview where I stated:

If you choose to embed all source files, you don't need this tool.

Were you asking how to embed all source files instead of enabling source link? If so, have a look at:

C:\Program Files\dotnet\sdk\1.0.0\Roslyn\Microsoft.CSharp.Core.targets

You will see that the C# Compiler takes in a @(EmbeddedFiles) MSBuild ItemGroup.

    <Csc  Condition=" '%(_CoreCompileResourceInputs.WithCulture)' != 'true' "
          EmbeddedFiles="@(EmbeddedFiles)"

You can do something similar to what I did here with Directory.Build.targets for the Paket pull request and just remove the condition. This should work for both C# and F#:

<Project>
  <PropertyGroup>
    <BuildDependsOn>EmbedAllFiles;$(BuildDependsOn)</BuildDependsOn>
  </PropertyGroup>
  <Target Name="EmbedAllFiles">
    <ItemGroup>
      <EmbeddedFiles Include="$([System.IO.Path]::GetFullPath('%(Compile.Identity)'))" />
    </ItemGroup>
    <CreateProperty Value="@(EmbeddedFiles)">  
      <Output TaskParameter="Value" PropertyName="embed" />  
    </CreateProperty>
  </Target>
</Project>

If it just C#, probably this will work:

<Project>
  <PropertyGroup>
    <BuildDependsOn>EmbedAllFiles;$(BuildDependsOn)</BuildDependsOn>
  </PropertyGroup>
  <Target Name="EmbedAllFiles">
    <ItemGroup>
      <EmbeddedFiles Include="%(Compile.Identity)" />
    </ItemGroup>
  </Target>
</Project>

Hope that helps.

@ctaggart
Copy link
Owner

ctaggart commented Apr 8, 2017

You can test if it worked by using dotnet sourcelink print-urls. It will list off each document and instead of the url, it will print embed.

@shaynevanasperen
Copy link
Author

Thanks @ctaggart. I think this approach would be my fallback in case I can't get it working properly with linking to GitHub. I'm having some trouble with that approach as well though. I'll comment here with any further information when I've gotten to the bottom of it.

@cwe1ss
Copy link

cwe1ss commented Apr 30, 2017

As a reference for other people, I finally got this working with the following Directory.Build.targets file:

<Project>
  <Target Name="PopulateEmbeddedFiles" AfterTargets="BeforeCompile" BeforeTargets="CoreCompile"
    Condition="'$(Configuration)'=='Release'">

    <Message Importance="High" Text="  SKIPPED source file embedding for $(MSBuildProjectName) - DebugType: $(DebugType)"
      Condition="'$(DebugType)'!='embedded' and '$(DebugType)'!='portable'" />

    <Message Importance="High" Text="$(MSBuildProjectName) -> Embedding source files"
      Condition="'$(DebugType)'=='embedded' or '$(DebugType)'=='portable'" />

    <ItemGroup Condition="'$(DebugType)'=='embedded' or '$(DebugType)'=='portable'">
      <EmbeddedFiles Include="@(Compile)" />
    </ItemGroup>
  </Target>
</Project>

Obviously, the Message-steps are just for troubleshooting.

Also have a look at dotnet/roslyn#19127 which should make this obsolete by exposing /embed to MSBuild.

@cwe1ss
Copy link

cwe1ss commented Apr 30, 2017

Turns out I cheered to soon. 😢 If I embed the source files on a build server (windows) it no longer works.

If I look at the generated DLL (from the nuget package), dotnet sourcelink print-urls returns the following for a file:

eba31d1dd082d4e65d34cdcd15ca9955457ae3d4 sha1 csharp C:\agent\_work\34\s\src\Meceqs.Abstractions\Envelope.cs
embedded

If I try to step into this file in Visual Studio 2017, it fails to load the file and outputs this. Note that the hash is the same.

Locating source for 'C:\agent\_work\34\s\src\Meceqs.Abstractions\Envelope.cs'. Checksum: SHA1 {eb a3 1d 1d d0 82 d4 e6 5d 34 cd cd 15 ca 99 55 45 7a e3 d4}
The file 'C:\agent\_work\34\s\src\Meceqs.Abstractions\Envelope.cs' does not exist.
Looking in script documents for 'C:\agent\_work\34\s\src\Meceqs.Abstractions\Envelope.cs'...
Looking in the Edit-and-Continue directory 'C:\src\tmp\ConsoleApp2\enc_temp_folder\'...
The file with the matching checksum was not found in the Edit-and-Continue directory.
Looking in the projects for 'C:\agent\_work\34\s\src\Meceqs.Abstractions\Envelope.cs'.
The file was not found in a project.
The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: C:\agent\_work\34\s\src\Meceqs.Abstractions\Envelope.cs.
The debugger could not locate the source file 'C:\agent\_work\34\s\src\Meceqs.Abstractions\Envelope.cs'.

Any ideas?

@shaynevanasperen
Copy link
Author

@cwe1ss I noticed that I couldn't step into some files when the code is compiled in Release, but I can if the code is compiled in Debug.

@cwe1ss
Copy link

cwe1ss commented Apr 30, 2017

@shaynevanasperen same result in my case. thx though!

@KirillOsenkov
Copy link

I think the debugger doesn't yet support extracting source files embedded in the .pdb.

@cwe1ss
Copy link

cwe1ss commented May 1, 2017

That's a bummer. I got really excited about this! 😢 This sounded like the perfect solution for internal libraries that sit in private repos. I'd still prefer this over enabling authenticated access to the repo because DLL size is not really a concern for our libraries and having to download each file separately seems unnecessary and slower.

Do you know of any place on GitHub where I can vote for this?

@KirillOsenkov
Copy link

Hopefully @gregg-miskelly will get to it at some point soonish...

Keep in mind though that the /embed option embeds the sources in the .pdb, not the .dll (unless of course you're embedding the .pdb itself in the .dll).

@gregg-miskelly
Copy link

I added a user voice item that folks can vote for and track progress: https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/19107733-debugger-should-support-c-compiler-embed-optio

@cwe1ss
Copy link

cwe1ss commented May 1, 2017

Awesome! I gave it my vote! thank you!

Note that the link in your uservoice comment links to itself... not sure if this was intended?!

@gregg-miskelly
Copy link

@cwe1ss Thanks for noticing. Fixed.

@ctaggart
Copy link
Owner

ctaggart commented May 2, 2017

I created a SourceLink.Embed.AllSourceFiles nupkg and released it with 2.1.1 just now. It is documented in the readme.

The 2 user issues that @gregg-miskelly added yesterday as well as the lack of pdb pack support are now in the readme too under Known Issues.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants