是否可以从使用dotnet build创建的.NET程序集中删除完整路径? [英] Is it possible to remove the full-paths from .NET assemblies created with dotnet build?
问题描述
我用 dotnet build
构建我的项目,目标是 netcoreapp3.1
.
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
这意味着程序集的哈希值取决于构建代码的目录.我希望它仅取决于源文件的哈希值和.NET SDK本身.
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.
是否有一种方法可以使 dotnet构建
使用这样的相对路径?
Is there a way to make dotnet build
use relative paths like this?
./my-app/App.fs
推荐答案
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>
项目根目录中的以下 Directory.Build.props
应该起作用:
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>
这篇关于是否可以从使用dotnet build创建的.NET程序集中删除完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!