I know this question is almost six years old but this is again an issue today, with Visual Studio 2019. I have confirmed it with 16.10.2 and 16.10.3 (may be more). Building a .Net 3.5 application left me with non-working resource dll's, which puzzled me until I found your question that hinted to investigate the resource dll .Net version, discovering that these were indeed linked to .Net 4 mscorlib instead of 3.5.
Problem confirmation
First confirm the issue.
In Visual Studio, go to Tools / Options / Projects and Solutions /
Build and Run and set MS Build project build output verbosity to
at least Normal (default is Minimal).
Rebuild your .Net 3.5 project.
In the Output / Build window look for the task GenerateSatelliteAssemblies:.
The command line below shows C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\al.exe
, which is the .Net 4.8 version of the assembly linker. On an unaffected system, that should have been C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\al.exe
.
So far the same problem as mentioned in the link by hultqvist's comment on the question. The cause and solution is different, however. The registry keys that are mentioned there, were perfectly fine on my system.
TL;DR - Solution (Workaround)
- Go to
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets
(exact path may differ a bit on your system, e.g. Professional instead of Enterprise).
- Create a backup copy of this file.
- Edit the file, and find a line containing the text
_ALExeToolPath
. It should be around line 3739. Looks like this:
<PropertyGroup>
<_ALExeToolPath>$(TargetFrameworkSDKToolsDirectory)</_ALExeToolPath>
<_ALExeToolPath Condition="'$(PlatformTarget)' == 'x64'">$(TargetFrameworkSDKToolsDirectory)$(PlatformTarget)\</_ALExeToolPath>
</PropertyGroup>
- Now scroll a bit down into the
AL
tag below and find the SdkToolsPath
attribute.
<AL AlgorithmId="$(Satellite_AlgorithmId)"
BaseAddress="$(Satellite_BaseAddress)"
...
SdkToolsPath="$(SdkToolsPathMaybeWithx64Architecture)" <!-- this is incorrect -->
- Change the value of the attribute from
$(SdkToolsPathMaybeWithx64Architecture)
to $(_ALExeToolPath)
- Save the file (needs elevation, probably)
- Rebuild your project, the correct linker is used and your resource dll's will work again.
Cause
This issue was introduced here to fix a minor issue with the assembly linker when targeting x64 vs x86. If you follow the comment thread with that PR you will spot the mistake: the actual variable in the fix is renamed after discussion, but they forgot to update that in the AL attribute before the PR was merged.
Because of this, the sdk tools path for al.exe is empty (it mentions a non-existing variable) and that causes msbuild to always call the default, which is usually the x86 version of the newest installed framework sdk on your system -- instead of a version that matches the version of your project.
That version of the .targets
file has been rolled out with a VS update.
They have since then spotted the mistake and fixed it. That fix has not rolled out as of today. If I understand the discussion correctly it is targeted for publish with v16.11.
If you cannot wait for that, follow the workaround I described above.