Use this article to troubleshoot issues that occur when a Visual Studio or MSBuild project uses the Dotfuscator MSBuild Targets, including projects configured by following the Protect Your App instructions.
Resolve Missing MSBuild Targets
If a project file, such as a .csproj or .vbproj file, imports the Dotfuscator MSBuild Targets, the targets file must be installed before Visual Studio can load the project or MSBuild can build it.
For example:
<Import Project=".../PreEmptive.Dotfuscator.Common.targets"/>You can install the required targets through:
- The Dotfuscator Windows Installer.
- The PreEmptive.Protection.Dotfuscator.Pro NuGet package.
If Dotfuscator is installed but Visual Studio still cannot load or build the project, review the directory from which the project imports the targets file. This directory normally appears in the error message:
error MSB4019: The imported project "C:\Program Files\MSBuild\PreEmptive\Dotfuscator\7\PreEmptive.Dotfuscator.Common.targets" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.The correct directory depends on how you installed Dotfuscator. For more information, refer to Locating the MSBuild Components.
Review the DotfuscatorMSBuildDir Property
The User Guide recommends storing the directory containing the targets file in the DotfuscatorMSBuildDir MSBuild property. This allows the path to vary across developer and build environments.
For example:
<Import Project="$(DotfuscatorMSBuildDir)/PreEmptive.Dotfuscator.Common.targets"/>If the error message displays an incorrect directory, determine where the DotfuscatorMSBuildDir property is being set.
The property can be set in the following locations:
- The project file.
- Another MSBuild property or targets file imported by the project.
- A Directory.Build.props file.
- A Directory.Build.targets file.
- An environment variable.
- A command-line variable passed to msbuild or dotnet.
MSBuild property names are not case-sensitive.
The following example sets the property to the location used by the Windows Installer if the property does not already have a value:
<PropertyGroup>
<DotfuscatorMSBuildDir Condition="'$(DotfuscatorMSBuildDir)' == ''">$(MSBuildProgramFiles32)/MSBuild/PreEmptive/Dotfuscator/7</DotfuscatorMSBuildDir>
</PropertyGroup>The following example imports a .dotfuscator.user.props file from the current user’s directory:
<Import Project="$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))/.dotfuscator.user.props"
Condition="Exists('$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))/.dotfuscator.user.props')"/>Determine Whether Dotfuscator Causes the Build Failure
Build a project configuration without Dotfuscator enabled.
If the error continues when Dotfuscator is disabled, the problem may be caused by another part of the project or build process.
Collect Additional Build Information
If the build displays only a generic message indicating that Dotfuscator failed or exited with an error code, increase the available logging:
- Set the Visual Studio build output verbosity, or the MSBuild -v option, to Normal or a more detailed level.
- Set Build Progress in the Dotfuscator configuration file to Verbose.
These settings display additional Dotfuscator information in the project’s build output.
Resolve DotfuscatorIncludeAsInput Errors and Warnings
The following errors and warnings can occur when using the DotfuscatorIncludeAsInput project property or metadata.
For more information about this feature, refer to Controlling Which Assemblies Are Protected.
Conflicting DotfuscatorIncludeAsInput Metadata
You may encounter the following error:
References to the assembly "X.dll" have conflicting 'DotfuscatorIncludeAsInput' metadata.
This error occurs when two Reference items for the same assembly assign different values to DotfuscatorIncludeAsInput.
For example, one project may include the assembly:
<Reference Include="ExternalAssembly">
<HintPath>../path/to/the/assembly/ExternalAssembly.dll</HintPath>
<DotfuscatorIncludeAsInput>true</DotfuscatorIncludeAsInput>
</Reference>Another project may exclude it:
<Reference Include="ExternalAssembly">
<HintPath>../path/to/the/assembly/ExternalAssembly.dll</HintPath>
<DotfuscatorIncludeAsInput>false</DotfuscatorIncludeAsInput>
</Reference>To resolve the error:
- Determine whether the assembly should be protected.
- Locate every reference to the assembly.
- Assign the appropriate DotfuscatorIncludeAsInput value consistently.
Protected and Unprotected Projects Share a Reference
You may encounter the following warning:
Some Projects that reference 'X.csproj' (directly or indirectly) have the 'DotfuscatorIncludeAsInput' property set to 'false', while other such projects do not.
This warning occurs when both a protected project and an unprotected project reference the same project.
For example, Projects A and B may both reference Project C. If Project A is protected and Project B is not, Dotfuscator protects Project C by default because a protected project references it.
If renaming is enabled, Project B may then attempt to reference methods or properties in Project C that Dotfuscator renamed.
To avoid this problem:
- Enable Library Mode for the shared project.
- Or exclude the shared project from Dotfuscator.
To exclude the shared project:
<!-- In ProjC.csproj -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DotfuscatorIncludeAsInput>false</DotfuscatorIncludeAsInput>
</PropertyGroup>
</Project>DotfuscatorIncludeAsInput Is Set on a ProjectReference
You may encounter the following error:
DotfuscatorIncludeAsInput was set on ProjectReference '../ProjB/ProjB.csproj' in project 'ProjA.csproj', but Dotfuscator does not honor this metadata on ProjectReference items.
The DotfuscatorIncludeAsInput metadata is not supported on ProjectReference items.
Remove the metadata from the ProjectReference:
<!-- In ProjA.csproj -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectReference Include=".../path/to/ProjectFile.csproj">
<!-- Remove DotfuscatorIncludeAsInput from this item. -->
</ProjectReference>
</ItemGroup>
</Project>Then add the DotfuscatorIncludeAsInput property to a PropertyGroup in the referenced project:
<!-- In ProjB.csproj -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DotfuscatorIncludeAsInput>false</DotfuscatorIncludeAsInput>
</PropertyGroup>
</Project>DotfuscatorIncludeAsInput Is Set on a PackageReference
You may encounter the following error:
DotfuscatorIncludeAsInput was set on PackageReference 'PackageName' in project 'Proj.csproj', but this version of Dotfuscator does not support including NuGet packages as inputs.
The DotfuscatorIncludeAsInput metadata is not supported on PackageReference items. Remove the metadata from the reference:
<!-- In Proj.csproj -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="PackageName" Version="1.2.3">
<!-- Remove DotfuscatorIncludeAsInput from this item. -->
</PackageReference>
</ItemGroup>
</Project>