Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to remove the full-paths from .NET assemblies created with dotnet build?

I build my project with dotnet build, targeting netcoreapp3.1.

The problem is that the assemblies contain the full path to the source-files:

/home/runner/my-app/App.fs

This means that the hash of the assemblies depends on the directory where the code was built. I want it to only depend on the hash of the source-files and the .NET SDK itself.

Is there a way to make dotnet build use relative paths like this?

./my-app/App.fs
like image 486
sdgfsdh Avatar asked Jan 28 '21 11:01

sdgfsdh


1 Answers

You can configure a release build with less information or you can override PathMap value to override it.

<PropertyGroup Label="Override Stack trace file locations">
  <PathMap>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=./</PathMap>
</PropertyGroup>

The following Directory.Build.props in the root of the project should work:

<Project>
 <PropertyGroup>
    <Deterministic>true</Deterministic>
    <DeterministicSourcePaths>true</DeterministicSourcePaths>
    <PathMap>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=./</PathMap>
 </PropertyGroup>
</Project>
like image 152
cdev Avatar answered Sep 19 '22 09:09

cdev