-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeLoadException when VSINSTALLDIR is set #4782
Comments
I'm having the same issue with DocFx 2.43.2. |
I am having the same issue with DocFx 2.44.0.0.
|
Seeing the same issue with DocFX 2.47.0 and from source 4b6abf5 The workaround with the VSINSTALLDIR environment variable doesn't appear to work for me. |
@sgrassie That should be another issue. This issue fixes that setting VSINSTALLDIR makes docfx not working properly, while unsetting it can work. |
fixed since 2.47 |
Operation System:
Windows
DocFX Version Used:
2.43.1.0
or
from source, commit 9a220bd
Template used:
default
Steps to Reproduce:
Set VSINSTALLDIR to the Visual Studio location.
Run
docfx metadata
on the docfx-seed project (or any project)or
attempt to run the unit tests from the build.
Expected Behavior:
Metadata is built,
or
Unit tests pass
Actual Behavior:
Metadata is not created and warning is logged:
Other projects will have the build fail, with the above warning followed by a NullReferenceException
or
Unit tests fail
Running in the debugger, the assemblies that can not be loaded are
Workaround
Unset the VSINSTALLDIR variable.
docfx metadata
succeeds and unit tests pass.Analysis
The MSBuild assemblies are not in the docfx folder, and must be resolved with an AssemblyResolve event. This is done by MsBuildLocator:
https://github.com/microsoft/MSBuildLocator/blob/8b5c58f5842f58ebf860ece96ac0f6924df839b1/src/MSBuildLocator/MSBuildLocator.cs#L191
Normally, this would be called in MsBuildEnvironmentScope:
docfx/src/Microsoft.DocAsCode.Metadata.ManagedReference/MsBuildEnvironmentScope.cs
Line 99 in af3345c
However, if VSINSTALLDIR is set, MsBuildEnvironmentScope exits early:
docfx/src/Microsoft.DocAsCode.Metadata.ManagedReference/MsBuildEnvironmentScope.cs
Lines 31 to 34 in af3345c
When this happens, MsBuildLocator is never called, the AssemblyResolve event handler is not added, and the assemblies are not found. It appears that setting MSBUILD_EXE_PATH will cause the same problem.
It seems like
MsBuildLocator.RegisterMSBuildPath
or similar should be called when the environment variables are set.The text was updated successfully, but these errors were encountered: