Mike
Mike

Reputation: 2510

TFS 2017 - Error MSB4126: The specified solution configuration "dev|any cpu" is invalid

This problem seems to be fairly common but I have yet to find a consistent solution.

I'm building a whole suite of 4.6.1 class libraries using VS2017 and TFS2017 - some will be nugets and some will be plugins - and I can't get one of the projects to build, despite using the same approach as all the previous projects.

We build all our projects using the platform "Any CPU" and configuration of either "dev", "test", "train" or "prod" - this has worked fine for years using TFS2013 and for at least 30 projects so far migrated over to the 2017 build system.

However, on one quite simple project, I keep getting the error...

Error MSB4126: The specified solution configuration "dev|any cpu" is invalid.

This is despite the configuration and platform being passed in from the build correctly as "dev" & "any cpu" and both the solution and project files both having the correct configurations set up...

sln:

Microsoft Visual Studio Solution File, Format Version 12.00
Visual Studio 15
VisualStudioVersion = 15.0.27703.2042
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MailMessageSerialisation", "MailMessageSerialisation\MailMessageSerialisation.csproj", "{9D787499-7DBB-4760-8923-C86FD13C4394}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        dev|Any CPU = dev|Any CPU
        prod|Any CPU = prod|Any CPU
        test|Any CPU = test|Any CPU
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {9D787499-7DBB-4760-8923-C86FD13C4394}.dev|Any CPU.ActiveCfg = dev|Any CPU
        {9D787499-7DBB-4760-8923-C86FD13C4394}.dev|Any CPU.Build.0 = dev|Any CPU
        {9D787499-7DBB-4760-8923-C86FD13C4394}.prod|Any CPU.ActiveCfg = prod|Any CPU
        {9D787499-7DBB-4760-8923-C86FD13C4394}.prod|Any CPU.Build.0 = prod|Any CPU
        {9D787499-7DBB-4760-8923-C86FD13C4394}.test|Any CPU.ActiveCfg = test|Any CPU
        {9D787499-7DBB-4760-8923-C86FD13C4394}.test|Any CPU.Build.0 = test|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {2C7FB0D0-7327-4D21-9A11-0B34AC019E68}
    EndGlobalSection
    GlobalSection(TeamFoundationVersionControl) = preSolution
        SccNumberOfProjects = 2
        SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
        SccTeamFoundationServer = http://XXXXXXXXX:8080/tfs/infrastructure
        SccLocalPath0 = .
        SccProjectUniqueName1 = MailMessageSerialisation\\MailMessageSerialisation.csproj
        SccProjectName1 = MailMessageSerialisation
        SccLocalPath1 = MailMessageSerialisation
    EndGlobalSection
EndGlobal

csproj:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">dev</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{9D787499-7DBB-4760-8923-C86FD13C4394}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MailMessageSerialisation</RootNamespace>
    <AssemblyName>MailMessageSerialisation</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkProfile />
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'dev|AnyCPU'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\dev\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <DebugType>full</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'test|AnyCPU'">
    <OutputPath>bin\test\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'prod|AnyCPU'">
    <OutputPath>bin\prod\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <!--
snip
  -->
</Project>

Build solution step of build output:

    ******************************************************************************
Starting: Build solution **\*.sln
******************************************************************************
==============================================================================
Task         : Visual Studio Build
Description  : Build with MSBuild and set the Visual Studio version property
Version      : 1.119.0
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613727)
==============================================================================
"E:\ci\builds\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -latest -format json
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation.sln" /nologo /nr:false /dl:CentralLogger,"E:\ci\builds\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=8659b024-ac52-47a4-a6ab-1be44fd5e1f8|SolutionDir=e:\ci\builds\61\s\MailMessageSerialisation\dev"*ForwardingLogger,"E:\ci\builds\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:platform="any cpu" /p:configuration="dev" /p:VisualStudioVersion="15.0" /p:_MSDeployUserAgent="TFS_620f346c-98e2-4693-ab12-3a966e56835f_build_66_333"
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 30/07/2018 3:34:36 PM.
Project "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "dev|any cpu".
Project "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation.sln" (1) is building "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.csproj" (2) on node 1 (default targets).
PrepareForBuild:
  Creating directory "bin\dev\".
  Creating directory "obj\dev\".
CoreCompile:
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:AnyCPU /errorreport:prompt /define:DEBUG;TRACE /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll" /reference:e:\ci\builds\61\s\MailMessageSerialisation\dev\packages\S22.SerializableMailMessage.1.0.5742.24665\lib\net46\S22.Mail.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Net.dll" /debug+ /debug:full /filealign:512 /out:obj\dev\MailMessageSerialisation.dll /ruleset:"C:\Program Files (x86)\Micros...
  Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn
_CopyFilesMarkedCopyLocal:
  Copying file from "e:\ci\builds\61\s\MailMessageSerialisation\dev\packages\S22.SerializableMailMessage.1.0.5742.24665\lib\net46\S22.Mail.dll" to "bin\dev\S22.Mail.dll".
  Creating "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\obj\dev\MailMessageSerialisation.csproj.CopyComplete" because "AlwaysCreate" was specified.
CopyFilesToOutputDirectory:
  Copying file from "obj\dev\MailMessageSerialisation.dll" to "bin\dev\MailMessageSerialisation.dll".
  MailMessageSerialisation -> e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\bin\dev\MailMessageSerialisation.dll
  Copying file from "obj\dev\MailMessageSerialisation.pdb" to "bin\dev\MailMessageSerialisation.pdb".
Done Building Project "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.csproj" (default targets).
Done Building Project "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation.sln" (default targets).
Build succeeded.
    0 Warning(s)
    0 Error(s)
Time Elapsed 00:00:01.28
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.sln" /nologo /nr:false /dl:CentralLogger,"E:\ci\builds\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=52be2739-dbca-4b96-a2a2-1bbd66410e14|SolutionDir=e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation"*ForwardingLogger,"E:\ci\builds\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.119.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:platform="any cpu" /p:configuration="dev" /p:VisualStudioVersion="15.0" /p:_MSDeployUserAgent="TFS_620f346c-98e2-4693-ab12-3a966e56835f_build_66_333"
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 30/07/2018 3:34:38 PM.
e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.sln.metaproj(0,0): Error MSB4126: The specified solution configuration "dev|any cpu" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration.
Project "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.sln" on node 1 (default targets).
e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.sln.metaproj : error MSB4126: The specified solution configuration "dev|any cpu" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration. [e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.sln]
Done Building Project "e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.sln" (default targets) -- FAILED.
Build FAILED.
"e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.sln" (default target) (1) ->
(ValidateSolutionConfiguration target) -> 
  e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.sln.metaproj : error MSB4126: The specified solution configuration "dev|any cpu" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration. [e:\ci\builds\61\s\MailMessageSerialisation\dev\MailMessageSerialisation\MailMessageSerialisation.sln]
    0 Warning(s)
    1 Error(s)
Time Elapsed 00:00:00.15
Process 'msbuild.exe' exited with code '1'.
******************************************************************************
Finishing: Build solution **\*.sln
******************************************************************************

As you can see, there is a "dev|any cpu" configuration in both the project and solution and the build is being told to use those settings...

... /p:platform="any cpu" /p:configuration="dev" ...

I've tried recreating the solution file, using different case for the parameters, skipping one (doesn't work), skipping both (works but doesn't allow for the config to be changed according to target environment), I've tried entering the parameters directly in the build definition step and also via build variables, all to no avail.

I have had this happen on one other project before, about a week ago, and on that occasion was only able to fix it by deleting the project entirely from TFS and completely reconstructing the project and solution (keeping only the class files from the original) and finally reconstructing the builds - the problem then went away! I assumed corruption somewhere but now it's happened again...

I can't post the full build step log here, it's too big, but I've done this dozens of times and cannot understand why this project should be any different from any of the others of a very similar nature, all which use the same solution/project structure and the same steps and parameters in the build definitions and all which work.

I don't want to have to rebuild the entire project, solution and build definitions each time I hit this problem - I have a heap of other projects to transition for 2013, some of which are far more complex.

Thoughts? Suggestions? (Please!)

Edit: For simplicity, I excluded the unit test project from the solution. Just adding it back in for further testing I discovered that it built just fine, despite being identically configured when compared to the original library project! Umm...

Edit2: Simply adding another build definition (built from scratch, not cloned) does not solve the problem, it appears to be an attribute of the project within the collection. Have raised a Premium Support case with MS.

Edit3: I've confirmed this isn't a code issue. I copied the file structure for a "broken" project, created a new project in the collection and imported the code, then hand crafted the build again - identical to the broken one - and the project built!

I can also, I believe, exclude the Export/Import Build Definition extension I added to TFS. I exported one of the broken build definitions, changed only the name in the JSON and imported it into the new project - it worked!

Upvotes: 0

Views: 1866

Answers (1)

Mike
Mike

Reputation: 2510

The problem is a combination of changes to the build system in 2017 vs the XAML builds and a little bit of laziness/untidiness on the part of a developer (who shall remain nameless).

Under normal circumstances in TFS we have...

<project name>
    \dev
        \project 0
        \project 1
        \etc.

When the first project is created, VS automatically creates a solution file in the same folder as the project. If this is moved/saved up to the dev folder before first check-in, all will be happy with the world.

Unfortunately this doesn't often occur until the project(s) have been saved into TFS, so we get...

<project name>
    \dev
        \project0
            project.sln
            project0.csproj
        \project1
            project1.csproj
        \etc.

Once the error is discovered, the developer resaves the .sln file to the dev folder and checks it in - there are now two solution files in the project but the second one is rarely seen and is forgotten.

<project name>
    \dev
        project.sln
        \project0
            project.sln    <- Problem!
            project0.csproj
        \project1
            project1.csproj
        \etc.

If the project is opened from source control, the second .sln isn't downloaded which is why copying the code to a new location would work - the code had been cleaned by opening the solution and downloading just the valid content.

The new build system downloads the entire dev branch and the build step is told (by default) to build **\*.sln - which finds both solution files. BTW The old XAML build system specified the path to the one correct .sln file so the problem didn't manifest itself.

If the configuration manager settings for dev, test, train and prod were setup before the .sln file was moved, the second solution will contain the correct values and build happily, simply slowing down the build step a bit. If, however, it still contains just Debug and Release, this does not match the parameters and the build fails.

My thanks to Martin at Microsoft Premium Support for poring over some serious size logs and finding this little needle in the haystack.

Upvotes: 1

Related Questions