解决 dotnet6 裁剪未使用的代码后报错

dotnet发布时可以裁剪不用的代码, 但有时候发布后会无法使用。 例如这种报错:

`System.MissingMethodException: Method not found: 'System.Threading.Tasks.ParallelLoopResult System.Threading.Tasks.Parallel.ForEach`

解决办法:

编辑.csproj文件,把缺失的库添加上去

<ItemGroup>
    <!--防止剪切掉-->
    <TrimmerRootAssembly Include="System.Threading.Tasks.Parallel" />
    <TrimmerRootAssembly Include="System.Collections.Concurrent" />    
</ItemGroup>

更多资料可以看这

https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/fixing-warnings