PublishSingleFile=true for .NET

The build 1932 supports self-contained executables.

Here is simple example of .csproj to protect compiled assembly before publishing in a single file:

<Project Sdk="Microsoft.NET.Sdk">

...

<Target Name="VMProtectCompile" BeforeTargets="GenerateSingleFileBundle">
  <PropertyGroup>
    <VMProtectCon>"C:\Program Files\VMProtect Demo\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>

</Project>

1、When I was testing this feature, I found that if the name of the project contains a space, it will report an error when publishing, please check, thank you.

2、At the same time, how to use functions such as ‘Memory Protection’, ‘Debugger’, ‘Virtualization Tools Found’ message, etc., which can be directly used in the gui?

Just change PATH_TO_VMP_FILE to the full name of “.vmp” file created by VMProtect’s GUI:

<Target Name="VMProtectCompile" BeforeTargets="GenerateSingleFileBundle">
  <PropertyGroup>
    <VMProtectCon>"C:\Program Files\VMProtect Demo\VMProtect_Con.exe"</VMProtectCon>
    <VMProtectInputFile>"$(IntermediateOutputPath)$(AssemblyName).dll"</VMProtectInputFile>
    <VMProtectProjectFile>-pf "PATH_TO_VMP_FILE"</VMProtectProjectFile>
  </PropertyGroup>
  <Exec Command="$(VMProtectCon) $(VMProtectInputFile) $(VMProtectInputFile) $(VMProtectProjectFile)" />
</Target>

About available parameters for the console version you can read here.

P.S. Don’t forget to use the code virtualization for all critical methods with ObfuscationAttribute:

[Obfuscation(Feature = "virtualization", Exclude = false)]
void MethodForProtection()
{
...

I don’t know if I understand it correctly, but I still get an error.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net8.0-windows</TargetFramework>
    <RootNamespace>Wpf_App</RootNamespace>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

<Target Name="VMProtectCompile" BeforeTargets="GenerateSingleFileBundle">
  <PropertyGroup>
    <VMProtectCon>"D:\VMProtect Demo\VMProtect_Con.exe"</VMProtectCon>
    <VMProtectInputFile>$(IntermediateOutputPath)$(AssemblyName).dll</VMProtectInputFile>
	<VMProtectProjectFile>-pf "C:\Users\Hao\Desktop\Wpf App\bin\Release\net8.0-windows\publish\win-x64\Wpf App.exe"</VMProtectProjectFile>
  </PropertyGroup>
  <Exec Command="$(VMProtectCon) $(VMProtectInputFile) $(VMProtectInputFile) $(VMProtectProjectFile)" />
</Target>

<Target Name="VMProtectDelete" AfterTargets="GenerateSingleFileBundle">
  <Delete Files="$(IntermediateOutputPath)$(AssemblyName).dll" />
</Target>

</Project>

It seems you don’t need our software, because you can’t even solve such a “simple problem” by yourself. I don’t understand why you think that “Wpf App.exe” is a VMProtect project file.

P.S. You still use wrong code here:

<VMProtectInputFile>$(IntermediateOutputPath)$(AssemblyName).dll</VMProtectInputFile>

Thank you very much, I successfully solved the problem, it was indeed that I used the wrong code.
ps. My English is not good, and I am not very familiar with this software, but now I understand what VMProtect project file is. Anyway, thank you again for your patient answer.

I have two questions about PublishSingleFile=true.

  1. Am I correct in assuming the console version is being used here?
    And it won’t work with a Lite license?

  2. I get the error:
    [Error] Can’t resolve assembly “Avalonia.Controls, Version=11.3.7.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b”
    namespae Avalonia.Controls is located in the Avalonia.dll assembly, which was added to the package as a NuGet package.
    What should I do to make VMProtect see it?

Please notice that the latest version of VMProtect supports self-contained EXE, so you don’t need to modify .csproj anymore.

I have the following structure in the .exe container:
cnc.dll - executable code with “main” function.
com.dll - assembly - where the main code is, included from cnc.dll
It’s com.dll that needs to be protected.

I can’t protect it even without linking to SingleFile.
Now I’m trying it on a regular Net application (without SingleFile).

And if I run VMProtect.exe on cnc.dll, everything is fine.
But if VMProtect.exe tries to protect com.dll, I get the error:
Can’t resolve type “System.Byte, System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” (token: 0xc0000eb)

So, it turns out that included assemblies can’t be protected?
Only the executable assembly can?
Is there a way out of this situation?

I hope I’ve explained everything clearly.

Please send us an example (original DLLs + .VMP files) that shows your problem.

I rebuilt the application to use a single executable DLL, but it didn’t help.
The error persists:
Can’t resolve type “System.Byte, System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” (token: 0xc0000eb)

Here’s the assembly’s bin directory:
https://drive.google.com/file/d/1gpPhPmIavrU5nDnTd5FaBeItDCs2CtVW/view?usp=sharing
The assembly needs to be protected: JupiterCNC.dll

Have a look?

Fixed in the 2503 build.

Thank you so much!

On the GUI on SinglFile:
Now the same thing, but with “CommunityToolkit.Mvvm”.
And this assembly is in “Imports” too.
???

If I run a simple application (not a SinglFile) from the GUI, compilation succeeds.
But the application won’t launch.
PS: In the code, I only set:
[Obfuscation(Feature = “strings”, Exclude = false)].
And I didn’t enable virtualization.

What could be causing it not to launch?

PS: In the Windows logs:

Application: JupiterCNC.exe
CoreCLR Version: 9.0.1025.47515
.NET Version: 9.0.10
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeLoadException: Could not load type ‘System.DoubleNumerics.Vector3’ from assembly 'JupiterCNC, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ due to value type mismatch.
at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
at System.Reflection.RuntimeMethodInfo.<get_Signature>g__LazyCreateSignature|25_0()
at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
at System.Reflection.RuntimeMethodInfo.GetParameters()
at InvokeStub_(Object, Span`1)
at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at System.Reflection.Emit.DynamicMethod.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at 563F5FA9.0FB29B3A()
at 563F5FA9.2EA869A8(Object 578EBD3D, Int32 7C01B93D)
— End of stack trace from previous location —
at 563F5FA9.4AB1E91F.F3333F1E(Object DFADEC00)
at 563F5FA9.2EA869A8(Object 578EBD3D, Int32 7C01B93D)
at 563F5FA9.DA17ED05()
at 563F5FA9.2EA869A8(Object 578EBD3D, Int32 7C01B93D)
— End of stack trace from previous location —
at 563F5FA9.4AB1E91F.F3333F1E(Object DFADEC00)
at 563F5FA9.2EA869A8(Object 578EBD3D, Int32 7C01B93D)
at .cctor()

PS: System.DoubleNumerics.dll is located in the bin directory, where ‘System.DoubleNumerics.Vector3’ is defined.

You should exclude renaming for all classes that used in reflection or switch off the option “Strip debug information”.

Thanks, but:

You wrote: >You should exclude renaming for all classes used in reflection

I don’t use Reflection anywhere in my code.
But I tried adding the tag to the project file:
false
But it didn’t work, the error was the same: Could not load type ‘System.DoubleNumerics.Vector3’
And the docs for “AutoGenerateBindingRedirects” say: It doesn’t apply to newer implementations of .NET, including .NET 6 and later versions.
So, you can no longer disable it in .NET projects.
Or did you mean something else, not “AutoGenerateBindingRedirects”?

You wrote: >or switch off the “Strip debug information” option

Disabled in the GUI.
This also didn’t work, the same error: Could not load type ‘System.DoubleNumerics.Vector3’
I checked with the following debug information types:
portable
full-
embedded

Fixed in the 2505 build.