Closed mwpowellhtx closed 6 years ago
It sounds like you're running from a copy of Microsoft.Build.*
assemblies that are up to date, but don't have an up-to-date copy of System.Collections.Immutable
available for resolution.
Are you deploying System.Collections.Immutable.dll
with your application? What version?
Are you using Microsoft.Build.Locator
? Mentioning that you've set environment variables makes me think you're not.
@rainersigwald Sounds accurate. I don't think so, re: Locator
. I'll try to enumerate my steps, although it's not a straight shot, per se, as I've got things more or less wired evently if you will for purposes of my unit test services:
using
statement ProjectCollection
instance pc
.pc
I predicate the Toolsets
based on ts.ToolsVersion=="15.0"
.ts.ToolsPath
GlobalProperties
dictionary to { {"Configuration", "Debug"}, {"Platform", "Any CPU"} }
, although ostensibly I might like to inject that via my test case arguments eventually.BuildParameters
including my TestLogger
(which provided the output above), i.e. new BuildParameters(pc) {Loggers = e.Loggers.ToArray()}
where pc
is the ProjectCollection
.new BuildRequestData(e.ProjectOrSolutionFullPath, e.GlobalProperties, ts.ToolsVersion, e.TargetsToBuild.ToArray(), null)
, where literally ProjectOrSolutionFullPath
is the path to my Solution or Project.var result = DefaultBuildManager.Build(parameters, requestData)
, for which I am given the expected result, namely Success
.The outer context has basically two steps:
NuGet Restore
on the Project or Solution, both of which seem to be working.Run
the actual build steps, enumerated above.The environment variables I am setting at the moment are:
SetEnvironmentVariable("VSINSTALLDIR", e.InstallDirectoryName);
SetEnvironmentVariable("MSBUILD_EXE_PATH", e.Toolset.ToolsPath);
SetEnvironmentVariable("VisualStudioVersion", e.Toolset.ToolsVersion);
Although, I'm not sure these are strictly necessary, at least they did not seem to be, but I could be mistaken there.
As far as references to System.Collections.Immutable
, there may be one such package reference in the test assembly itself. However,
<package id="System.Collections.Immutable" version="1.3.1" targetFramework="net462" />
I started with .NET Framework 4.6.2 as a nominal starting point, but I'm not attached there if need be. That to say, I could change the Target framework
for the unit test assembly? To 4.7.2
? Or even Core
?
Try updating to package version 1.5.0
. That delivers System.Collections.Immutable, Version=1.2.3.0
, which is what MSBuild (and VS 15.8) depend on.
That fixed it, thank you; I updated the *Microsoft.Build.** packages, for starters. Will make sure my packages are updated flush as needed.
Please do look at https://docs.microsoft.com/en-us/visualstudio/msbuild/updating-an-existing-application -- using Locator should help avoid these problems in the future, by ensuring you/your tests are using the same MSBuild that VS would on a given machine.
@rainersigwald Let me ask you this question following up; if I updated my package references from 15.7 15.8, does this mean that anyone rebuilding and running the same tests also needs to be on the same VS version? My take away's from that lead me to wonder if a bit of packaging/DLL hell isn't the natural consequence of this approach. Not to say package delivery isn't worthwhile; but it does carry with it a massive dependency implication. Is this an accurate assessment? Or is this the problem the Locator service attempts to solve?
That's exactly the problem the Locator is trying to solve. Prior to Visual Studio 2017, MSBuild was installed in the Global Assembly Cache, so any application that attempted to load it would get the same version. VS 2017 supports side-by-side installs, so MSBuild isn't in the GAC any more (so your Preview-channel MSBuild doesn't stomp on your release-channel MSBuild). That's mostly good, but it means that API clients have to do more work to get a consistent view of the world: either package everything that MSBuild needs (essentially impossible; it's not all open source and it's impossible to know what VS extensions someone may have installed) or locate and use the copy of MSBuild from their VS installation (which might mean picking among VS installations).
@rainersigwald Gotcha, thanks very much for the clarification. :+1:
I get the log below when I try to invoke the
BuildManager.Build
for a.csproj
Project.The same invocation for the containing
.sln
Solution works just fine. The output I receive is the usual set of unresolved assemblies:My log from the build using Detailed verbosity threshold:
Incidentally, I am preceding the call to
Build
with a programmaticNuGet Restore
, which itself seemed to be necessary, and also appears to be working, no errors, exit code 0, whether I specify the Solution file or the Project file.Background bits, I've identified the proper
15.0
Toolset, although perhaps I need to be on the latest15.8
? I'm not sure. Other than that, I am setting all the customary environment variables, etc, required to invokeMSBuild
viaMicrosoft.Build.Execution.BuildManager.DefaultBuildManager
, or so I believe.Let me know if you need any other notes, I will try to furnish them.
Thanks!