cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.87k stars 729 forks source link

MSBuild error MSB4062 not fails build #1606

Open sm-g opened 7 years ago

sm-g commented 7 years ago

What You Are Seeing?

What is Expected?

Build stopped with An error occurred when executing task 'Publish'.

What are you using?

cake 0.19.5, windows10-x64

How Did You Get This To Happen? (Steps to Reproduce)

Task("Publish")
    .IsDependentOn("Clean")
    .Does(() =>
{
    MSBuild(SOLUTION_FILE, settings => settings
        .WithTarget("Publish")
        .SetConfiguration(configuration)
        .SetVerbosity(Verbosity.Minimal)
        .UseToolVersion(MSBuildToolVersion.VS2017)
        .SetPlatformTarget(PlatformTarget.MSIL)
        //.SetMSBuildPlatform(MSBuildPlatform.x86) // MSB4062 will gone if uncomment, but I need failng build
    );
});

Output Log

Preparing to run build script...
Running build script...
Module directory does not exist.
Analyzing build script...
Analyzing C:/xxx/build.cake...
Processing build script...
Installing tools...
Package NUnit.ConsoleRunner has already been installed.
Installing addins...
Package Cake.Npm has already been installed.
The addin Cake.Npm will reference Cake.Npm.dll.
Creating script session...
Adding reference to mscorlib.dll...
Adding reference to System.Core.dll...
Adding reference to Cake.Core.dll...
Adding reference to Cake.Common.dll...
Adding reference to Cake.exe...
Adding reference to System.dll...
Adding reference to System.Xml.dll...
Adding reference to System.Xml.Linq.dll...
Adding reference to System.Data.dll...
Adding reference to Cake.Npm.dll...
Importing namespace Cake.Common...
Importing namespace Cake.Common.Build...
Importing namespace Cake.Common.Build.AppVeyor...
Importing namespace Cake.Common.Build.AppVeyor.Data...
Importing namespace Cake.Common.Build.Bamboo...
Importing namespace Cake.Common.Build.Bamboo.Data...
Importing namespace Cake.Common.Build.BitbucketPipelines...
Importing namespace Cake.Common.Build.BitbucketPipelines.Data...
Importing namespace Cake.Common.Build.Bitrise...
Importing namespace Cake.Common.Build.Bitrise.Data...
Importing namespace Cake.Common.Build.ContinuaCI...
Importing namespace Cake.Common.Build.ContinuaCI.Data...
Importing namespace Cake.Common.Build.GitLabCI...
Importing namespace Cake.Common.Build.GitLabCI.Data...
Importing namespace Cake.Common.Build.GoCD...
Importing namespace Cake.Common.Build.GoCD.Data...
Importing namespace Cake.Common.Build.Jenkins...
Importing namespace Cake.Common.Build.Jenkins.Data...
Importing namespace Cake.Common.Build.MyGet...
Importing namespace Cake.Common.Build.TeamCity...
Importing namespace Cake.Common.Build.TFBuild...
Importing namespace Cake.Common.Build.TFBuild.Data...
Importing namespace Cake.Common.Build.TravisCI...
Importing namespace Cake.Common.Build.TravisCI.Data...
Importing namespace Cake.Common.Diagnostics...
Importing namespace Cake.Common.IO...
Importing namespace Cake.Common.IO.Paths...
Importing namespace Cake.Common.Net...
Importing namespace Cake.Common.Security...
Importing namespace Cake.Common.Solution...
Importing namespace Cake.Common.Solution.Project...
Importing namespace Cake.Common.Solution.Project.Properties...
Importing namespace Cake.Common.Solution.Project.XmlDoc...
Importing namespace Cake.Common.Text...
Importing namespace Cake.Common.Tools...
Importing namespace Cake.Common.Tools.Cake...
Importing namespace Cake.Common.Tools.Chocolatey...
Importing namespace Cake.Common.Tools.Chocolatey.ApiKey...
Importing namespace Cake.Common.Tools.Chocolatey.Config...
Importing namespace Cake.Common.Tools.Chocolatey.Features...
Importing namespace Cake.Common.Tools.Chocolatey.Install...
Importing namespace Cake.Common.Tools.Chocolatey.New...
Importing namespace Cake.Common.Tools.Chocolatey.Pack...
Importing namespace Cake.Common.Tools.Chocolatey.Pin...
Importing namespace Cake.Common.Tools.Chocolatey.Push...
Importing namespace Cake.Common.Tools.Chocolatey.Sources...
Importing namespace Cake.Common.Tools.Chocolatey.Uninstall...
Importing namespace Cake.Common.Tools.Chocolatey.Upgrade...
Importing namespace Cake.Common.Tools.DotCover...
Importing namespace Cake.Common.Tools.DotCover.Analyse...
Importing namespace Cake.Common.Tools.DotCover.Cover...
Importing namespace Cake.Common.Tools.DotCover.Merge...
Importing namespace Cake.Common.Tools.DotCover.Report...
Importing namespace Cake.Common.Tools.DotNetCore...
Importing namespace Cake.Common.Tools.DotNetCore.Build...
Importing namespace Cake.Common.Tools.DotNetCore.Execute...
Importing namespace Cake.Common.Tools.DotNetCore.Pack...
Importing namespace Cake.Common.Tools.DotNetCore.Publish...
Importing namespace Cake.Common.Tools.DotNetCore.Restore...
Importing namespace Cake.Common.Tools.DotNetCore.Run...
Importing namespace Cake.Common.Tools.DotNetCore.Test...
Importing namespace Cake.Common.Tools.DupFinder...
Importing namespace Cake.Common.Tools.Fixie...
Importing namespace Cake.Common.Tools.GitLink...
Importing namespace Cake.Common.Tools.GitReleaseManager...
Importing namespace Cake.Common.Tools.GitReleaseManager.AddAssets...
Importing namespace Cake.Common.Tools.GitReleaseManager.Close...
Importing namespace Cake.Common.Tools.GitReleaseManager.Create...
Importing namespace Cake.Common.Tools.GitReleaseManager.Export...
Importing namespace Cake.Common.Tools.GitReleaseManager.Publish...
Importing namespace Cake.Common.Tools.GitReleaseNotes...
Importing namespace Cake.Common.Tools.GitVersion...
Importing namespace Cake.Common.Tools.ILMerge...
Importing namespace Cake.Common.Tools.ILRepack...
Importing namespace Cake.Common.Tools.InnoSetup...
Importing namespace Cake.Common.Tools.InspectCode...
Importing namespace Cake.Common.Tools.MSBuild...
Importing namespace Cake.Common.Tools.MSTest...
Importing namespace Cake.Common.Tools.NSIS...
Importing namespace Cake.Common.Tools.NuGet...
Importing namespace Cake.Common.Tools.NuGet.Add...
Importing namespace Cake.Common.Tools.NuGet.Init...
Importing namespace Cake.Common.Tools.NuGet.Install...
Importing namespace Cake.Common.Tools.NuGet.Pack...
Importing namespace Cake.Common.Tools.NuGet.Push...
Importing namespace Cake.Common.Tools.NuGet.Restore...
Importing namespace Cake.Common.Tools.NuGet.SetApiKey...
Importing namespace Cake.Common.Tools.NuGet.SetProxy...
Importing namespace Cake.Common.Tools.NuGet.Sources...
Importing namespace Cake.Common.Tools.NuGet.Update...
Importing namespace Cake.Common.Tools.NUnit...
Importing namespace Cake.Common.Tools.OctopusDeploy...
Importing namespace Cake.Common.Tools.OpenCover...
Importing namespace Cake.Common.Tools.ReportGenerator...
Importing namespace Cake.Common.Tools.ReportUnit...
Importing namespace Cake.Common.Tools.Roundhouse...
Importing namespace Cake.Common.Tools.SignTool...
Importing namespace Cake.Common.Tools.SpecFlow...
Importing namespace Cake.Common.Tools.SpecFlow.StepDefinitionReport...
Importing namespace Cake.Common.Tools.SpecFlow.TestExecutionReport...
Importing namespace Cake.Common.Tools.TextTransform...
Importing namespace Cake.Common.Tools.VSTest...
Importing namespace Cake.Common.Tools.VSWhere...
Importing namespace Cake.Common.Tools.VSWhere.All...
Importing namespace Cake.Common.Tools.VSWhere.Latest...
Importing namespace Cake.Common.Tools.VSWhere.Legacy...
Importing namespace Cake.Common.Tools.VSWhere.Product...
Importing namespace Cake.Common.Tools.WiX...
Importing namespace Cake.Common.Tools.WiX.Heat...
Importing namespace Cake.Common.Tools.XBuild...
Importing namespace Cake.Common.Tools.XUnit...
Importing namespace Cake.Common.Xml...
Importing namespace Cake.Core...
Importing namespace Cake.Core.Diagnostics...
Importing namespace Cake.Core.IO...
Importing namespace Cake.Core.Scripting...
Importing namespace Cake.Npm...
Importing namespace Cake.Npm.Install...
Importing namespace Cake.Npm.Pack...
Importing namespace Cake.Npm.RunScript...
Importing namespace System...
Importing namespace System.Collections.Generic...
Importing namespace System.IO...
Importing namespace System.Linq...
Importing namespace System.Text...
Importing namespace System.Threading.Tasks...
Compiling build script...

----------------------------------------
Setup
----------------------------------------
Executing custom setup action...
Will run target: publish for configuration Debug
Checking dotnet SDK...
Executing: "dotnet" --version
1.0.4
Executing custom task setup action (Clean)...

========================================
Clean
========================================
Executing task: Clean
The provided pattern did not match any directories.
The provided pattern did not match any directories.
Cleaning directory C:/xxx/publish
Finished executing task: Clean
Executing custom task teardown action (Clean)...
Executing custom task setup action (Publish)...

========================================
Publish
========================================
Executing task: Publish
Executing: "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/amd64/MSBuild.exe" /m /v:minimal /p:Configuration="Debug" /p:Platform="Any CPU" /p:PublishDir=C:/xxx/publish /target:Publish "C:/xxx/YYY.sln"
Microsoft (R) Build Engine версии 15.1.1012.6693
(C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.

  YYY.Models -> C:\xxx\src\YYY.Models\bin\Debug\YYY.Models.dll 
  YYY.WebApp -> C:\xxx\src\YYY.WebApp\bin\Debug\net461\win7-x64\YYY.WebApp.exe
  copy sql files...
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard
1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(54,5): error MSB4062: Невозможно загрузить задачу
 "TransformWebConfig" из сборки "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.
NET.Sdk.Publish\build\netstandard1.0\..\..\tools\net46\\Microsoft.NET.Sdk.Publish.Tasks.dll". Не удалось загрузить файл
 или сборку "file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publ
ish\tools\net46\Microsoft.NET.Sdk.Publish.Tasks.dll" либо одну из их зависимостей. Была сделана попытка загрузить прогр
амму, имеющую неверный формат. Проверьте правильность объявления <UsingTask>, доступность сборки со всеми ее зависимост
ями и наличие в задаче общего класса, реализующего Microsoft.Build.Framework.ITask. [C:\xxx\src\YYY.WebApp\YYY.WebApp
.csproj]
  YYY.WebApp.Tests -> C:\xxx\src\YYY.WebApp.Tests\bin\Debug\net461\win7-x64\YYY.WebApp.Tests.dll
Finished executing task: Publish
Executing custom task teardown action (Publish)...

----------------------------------------
Teardown
----------------------------------------
Executing custom teardown action...

Task                          Duration
--------------------------------------------------
Clean                         00:00:00.0164783
Publish                       00:00:04.2226169
--------------------------------------------------
Total:                        00:00:04.2390952
patriksvensson commented 7 years ago

@sm-g Could you translate the error message to English for us? Thanks!

sm-g commented 7 years ago

@patriksvensson error MSB4062: The "TransformWebConfig" task could not be loaded from the assembly "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft. NET.Sdk.Publish\build\netstandard1.0....\tools\net46\Microsoft.NET.Sdk.Publish.Tasks.dll". Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publ ish\tools\net46\Microsoft.NET.Sdk.Publish.Tasks.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loa ded. Confirm that the declaration is correct, and that the assembly and all its dependencies are available.

bjorkstromm commented 7 years ago

@sm-g

Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publ ish\tools\net46\Microsoft.NET.Sdk.Publish.Tasks.dll' or one of its dependencies.

This says it all. Cake is currently built for .NET 4.5 and can't therefore load .NET 4.6 assemblies.

Using Cake.CoreCLR instead (which is built for netstandard1.6) will most likely solve this issue. However, Cake.CoreCLR will not currently support all available addins.

This issue will be addressed in a not-so-distant-future.

sm-g commented 7 years ago

With .SetMSBuildPlatform(MSBuildPlatform.x86) there is no such error (will be fixed in Core 2.0 SDK 2.0). I do not think that is about Cake .net version, it invokes msbuild and msbuild cannot load assembly.

bjorkstromm commented 7 years ago

@sm-g ah, I see. Sorry didn't read the logs fully before answering.