Open mattaquinn opened 1 year ago
Digging into this deeper I am noticing that Microsoft.Build.* assemblies in C:\Program Files (x86)\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\ have FileName = 17.2.1.25201, but are signed as Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
I am not sure if this is expected or a contributing factor.
I'll also note that if I GAC these assemblies, then they are found. Should they be GAC'd? I see other lower versioned Microsoft.Build.* assemblies in the GAC.
Very interesting. I repro, and on my test project I can fix by adding
DisableInProcNode = true,
to the BuildParameters
. That forces the actual task execution into a copy of MSBuild.exe
spawned by the API as a worker node, rather than running it in-proc, which appears to work around a problem inside the task (I'm guessing caused by doing something with an AppDomain
inside the task).
Can you try that?
Digging into this deeper I am noticing that Microsoft.Build.* assemblies in C:\Program Files (x86)\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\ have FileName = 17.2.1.25201, but are signed as Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
I am not sure if this is expected or a contributing factor.
It's expected. We've kept the AssemblyVersion constant at 15.1.0.0
to minimize the need to update binding redirects when MSBuild updates, but the file version reports the "true" version.
I'll also note that if I GAC these assemblies, then they are found. Should they be GAC'd? I see other lower versioned Microsoft.Build.* assemblies in the GAC.
They should not be GACed. If you GAC them you'll run into problems on VS upgrades/updates and potentially break side-by-side installations of Visual Studio (for instance having Preview and release installed simultaneously).
@rainersigwald Thank you! This did the trick.
var parameters = new BuildParameters(pc)
{
Loggers = ...
DisableInProcNode = true
};
It appears the above work-around creates a different problem, whenever a solution has a build dependency the build fails with
error MSB4025: The project file could not be loaded. Could not find file 'Path\to\Some.csproj.metaproj'.
This seems to explain the problem best: https://github.com/dotnet/msbuild/issues/3517
If set MSBuildEmitSolution=1 it will work, but (as intended) will leave .metaproj files hanging around afterwards.
@rainersigwald is there any other option I can try?
I have the same problem. And, to me it seems to be a general problem (or misunderstanding) about how MSBuild finds something (e.g. the assemblies that it loads). Whenever I run MSBuild from my solution, it doesn't work or load the wrong MSBuild version. I had to pack it into its own AppDomain and register assembly paths in order to solve this. I guess, Visual Studio does something similar, but I didn't find out what it does. ... now, this seems to be a solution, but it causes problems, whenever something happens, that runs in its own domain (again, I have no idea how Visual Studio handles this so that all the settings is makes are still set when something runs in its own domain)... but here, with XAML compilation, we do have such a problem. My temporary solution was to set "AlwaysCompileMarkupFilesInSeparateDomain" to "false". ... but I have still other problems like e.g. I cannot build solutions with project dependencies, because all the "using" paths are wrong then.
so... would be nice to hear about how to prepare the "world" in order to be able to call MSBuild so that it then runs as if from within Visual Studio
I am attempting to use the Microsoft.Build API to build projects and solution for use in an application within my company that is converting thousands of csproj files to the SDK format and verifying the build before and after. I am running into an exception with WPF projects that are in the Framework format. If I convert the project to SDK, the build succeeds. I do not have this issue building within Visual Studio 2022 or using MSBuild in 2022 Developer Command prompt. When I dig into the the exception I find that the root cause is an FileNotFoundException loading 'Microsoft.Build.Framework, Version=15.1.0.0,...'
I am not sure if there is a problem with my installation or something with my code/setup. I have attached the results of EnumerateMSBuild.ps1 and included as much detail as I can think of below. Please let me know if you require any more information and thank you in advance for any guidance.
msbuild_versions.txt
The Error I get from the build is:
The diagnostic level log (abridged) has this information around the error:
When I attach a debugger and decompile symbols, I find the null ref is in the error handler on the "linePos" line, but the actual exception "e" is a file not found.
Actual exception:
My code: