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

穿精又带淫゛_ 提交于 2021-02-20 19:10:32

问题


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

回答1:


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>



回答2:


C# compiler (csc) has a compiler switch -deterministic

F# compiler (fsc) appears to have a switch --deterministic+

From looking at the DotNet SDK repo it appears there are 2 properties for project files:

<Deterministic>true</Deterministic>
<DeterministicSourcePaths>true</DeterministicSourcePaths>

You might not need both of these.



来源:https://stackoverflow.com/questions/65935784/is-it-possible-to-remove-the-full-paths-from-net-assemblies-created-with-dotnet

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