步骤:
打开对应项目的.csproj
文件,添加以下内容:
<Target Name="VMProtectCompile" BeforeTargets="GenerateSingleFileBundle">
<PropertyGroup>
<VMProtectCon>"D:\Program Files\VMProtect Ultimate\VMProtect_Con.exe"</VMProtectCon>
<VMProtectInputFile>"$(IntermediateOutputPath)$(AssemblyName).dll"</VMProtectInputFile>
</PropertyGroup>
<Exec Command="$(VMProtectCon) $(VMProtectInputFile) $(VMProtectInputFile)" />
</Target>
<Target Name="VMProtectDelete" AfterTargets="GenerateSingleFileBundle">
<Delete Files="$(IntermediateOutputPath)$(AssemblyName).dll" />
</Target>
注意:
修改
VMProtectCon
这个值为你VMProtect
的VMProtect_Con.exe
地址,通常在安装目录下生成的文件会先在
obj
文件下,通过这种方式生成可能会缺少相关引用库的DLL,具体解决办法见:https://gd520.cc/archives/vmprotect-jie-jue-can-t-resolve-assembly-newtonsoft.Json
如果想使用VMP
中的配置来生成,可以在项目的.csproj
文件中,添加 VMProtectProjectFile
并修改 "PATH_TO_VMP_FILE"
为自己的vmp
文件所在位置,例如:
<Target Name="VMProtectCompile" BeforeTargets="GenerateSingleFileBundle">
<PropertyGroup>
<VMProtectCon>"D:\Program Files\VMProtect Ultimate\VMProtect_Con.exe"</VMProtectCon>
<VMProtectInputFile>"$(IntermediateOutputPath)$(AssemblyName).dll"</VMProtectInputFile>
<VMProtectProjectFile>-pf "PATH_TO_VMP_FILE"</VMProtectProjectFile>
</PropertyGroup>
<Exec Command="$(VMProtectCon) $(VMProtectInputFile) $(VMProtectInputFile) $(VMProtectProjectFile)" />
</Target>
<Target Name="VMProtectDelete" AfterTargets="GenerateSingleFileBundle">
<Delete Files="$(IntermediateOutputPath)$(AssemblyName).dll" />
</Target>
点击生成即可