当构建尝试使用dotfuscator的.net核心应用程序时,我们可以使用msbuild.exe成功构建和混淆,但是使用.net core cli进行的任何构建或发布都将失败。

这些问题使用本地命令行存在,并且在我们的devops构建管道中也存在。

例子

msbuild.exe“项目文件.csproj”
dotnet build“项目文件.csproj”
dotnet发布“项目文件.csproj”
D:\ Repos \ PF \ tools \ dotfuscator \ PreEmptive.Dotfuscator.Common.targets(262,5):错误MSB4062:无法从程序集D:\ Repos \ PF \ tools \ dotfuscator \加载“ FindProjectAssemblies”任务PreEmptive.Dotfuscator.Internal.Tasks.dll。无法加载文件或程序集'Microsoft.Build.Utilities.v4.0,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'。该系统找不到指定的文件。确认声明正确,程序集及其所有依赖项均可用,并且任务包含实现Microsoft.Build.Framework.ITask的公共类。 [D:\ Repos \ PF \ source \ xxxxx.xxxxx.xxxxx.API \ xxxxx.xxxxxx.xxxxxx.API.csproj]

看起来非常像这个问题。
https://github.com/Microsoft/msbuild/issues/2111

最佳答案

更新(2019-12-20):我们发布了a beta version of Dotfuscator Professional 6.0.0,支持在非Windows操作系统上运行Dotfuscator。这包括对dotnet命令的支持。



Dotfuscator可以保护.NET Core程序集,这些程序集随后可以在.NET Core(即跨平台)下运行。但是,在撰写本文时,Dotfuscator本身仅可在基于Windows的经典.NET Framework上运行。

看来您已经将Dotfuscator Professional集成到the recommended way中的构建中,该构建使用Dotfuscator的MSBuild目标和任务。说明包括将此<Import>添加到您的项目文件中:

<Import Project="$(MSBuildExtensionsPath)\PreEmptive\Dotfuscator\4\PreEmptive.Dotfuscator.Common.targets"/>


当我为.NET Core项目执行此操作时,可以在Visual Studio中或通过msbuild /t:Publish /p:Configuration=Release进行构建,并获得受保护的应用程序。但是,如果我尝试运行dotnet build MyApp.csprojdotnet publish MyApp.csproj,则构建失败。我收到的错误信息与刚开始时不同:


错误MSB4019:找不到导入的项目“ C:\ Program Files \ dotnet \ sdk \ 2.1.503 \ PreEmptive \ Dotfuscator \ 4 \ PreEmptive.Dotfuscator.Common.targets”。确认声明中的路径正确,并且文件在磁盘上。


这是因为Dotfuscator不会将其MSBuild目标安装到.NET Core位置,仅安装到.NET Framework和Visual Studio位置,因此上面的<Import>找不到所需的文件。

如果我改为将MSBuild文件从C:\Program Files (x86)\MSBuild复制到我自己的位置(例如C:\DotfuscatorMSBuildCopy),并相应地更改<Import>

<Import Project="C:\DotfuscatorMSBuildCopy\PreEmptive\Dotfuscator\4\PreEmptive.Dotfuscator.Common.targets"/>


然后我看到你的错误:


错误MSB4062:无法从程序集C:\ DotfuscatorMSBuildCopy \ PreEmptive \ Dotfuscator \ 4 \ PreEmptive.Dotfuscator.Internal.Tasks.dll中加载“ FindProjectAssemblies”任务。无法加载文件或程序集'Microsoft.Build.Utilities.v4.0,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'。该系统找不到指定的文件。确认声明正确,程序集及其所有依赖项均可用,并且任务包含实现Microsoft.Build.Framework.ITask的公共类。


解决方案是使用msbuild /t:Publish /p:Configuration=Release而不是dotnet进行构建。

(注意:我为Dotfuscator团队工作,并以此身份回答。)

关于.net-core - 具有“dotnet构建”或“dotnet发布”的dotfuscator-无法加载“FindProjectAssemblies”任务PreEmptive.Dotfuscator.Internal.Tasks.dll,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54243003/

10-09 22:01