25

I have an MVC project that for an uknown reason refuses to publish to a local folder in the PC.

The log says the following:

3>------ Publish started: Project: Admin, Configuration: Release Any CPU ------
3>Connecting to D:\Deploys...
3>Project "Admin.csproj" (GatherAllFilesToPublish target(s)):
3>    Building with tools version "14.0".
3>    Target "ValidateMSBuildToolsVersion" skipped. Previously built unsuccessfully.
3>Done building project "Admin.csproj" -- FAILED.
3>
========== Build: 2 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========
========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

I haven't had a problem debugging on either release or debug config.

Hrodger
  • 1,278
  • 1
  • 11
  • 16
  • What does a more verbose output say? https://blogs.msdn.microsoft.com/saraford/2008/10/07/did-you-know-you-can-configure-the-msbuild-verbosity-in-the-output-window-329/ – Caramiriel Jan 04 '18 at 20:27
  • @Caramiriel Hi! I already have it on the "diagnostic" option. The "detailed" one also outputs the same. – Hrodger Jan 04 '18 at 20:28
  • try a clean/rebuild. restart visual studio. – Joseph Mawer Jan 04 '18 at 20:55
  • @JMawer Hi! Already did that. Delete obj/bin folders, restart VS, restart PC. – Hrodger Jan 04 '18 at 21:39
  • Perhaps you don't have permission to publish to that folder location? Have you tried installing to a location you are certain you have read/write permissions? – Joseph Mawer Jan 04 '18 at 21:43
  • See my answer - hope it helps https://stackoverflow.com/questions/8120812/publish-failed-but-build-succeeded/49354473#49354473 – Alexey Shevelyov Mar 19 '18 at 01:12

12 Answers12

67

So I made it work.

The problem was the version of the "Microsoft.Net.Compilers". I downgraded from v2.6.1 to v2.4.0.

I don't know why so if someone knows it would be cool to know.

Hrodger
  • 1,278
  • 1
  • 11
  • 16
  • 1
    Thanks this problem was getting on my nerves, would really want to know why this is happening. – Monroy Jan 10 '18 at 20:21
  • Not just an issue with web publish; I had the problem that my solution rebuild was always failing because of this (two MVC projects, one as a dependency of the other the second one would always fail if the first one still needed to be built). – Bjørn van Dommelen Jan 17 '18 at 14:11
  • 7
    According to [https://github.com/dotnet/roslyn/wiki/NuGet-packages] the 2+ versions of the compilers package are for VS2017 and C#7. Also see [https://github.com/dotnet/roslyn/issues/19128] for what's supported where. Why it actually works with 2.4 and not with 2.6.1 (it shouldn't work with 2.4 either); I can only imagine the build tasks were updated with 2.4 but not with 2.6.1 so 2.6.1 requires MSBUILD 15 again (VS2015 has MSBUILD 14). – Bjørn van Dommelen Jan 17 '18 at 14:34
  • Going to 2.4.0 fixed for me as well. Per dup suggestion here: https://stackoverflow.com/questions/48272051/publish-failed-build-succeeded?noredirect=1&lq=1#comment83528196_48272051 – Christopher Feb 23 '18 at 12:14
  • I had the same problem too! Thanks! – Federico Navarrete Mar 01 '18 at 09:38
  • I also had this problem (running under Visual Studio 2015). Upgrading Microsoft.Net.Compilers to 2.7.0 (published 2018-03-08) solved it. – Brian Diggs Mar 12 '18 at 14:44
  • 2
    Had the same, I just uninstalled .Net.Compilers. also solved the problem – Jaime Yule Mar 19 '18 at 14:36
  • What a PITA! Worked for me as well! – drogon Sep 10 '18 at 22:16
  • I used the VS2015 and got the same issue. this worked for me and fixed the issue – Telan Niranga Nov 01 '18 at 18:47
  • I resolved it by removing the compiler reference as it wasn't needed. Still don't know how it got added in the first place. – Thierry Jul 21 '21 at 08:12
2

Sorry for reopening the thread, but for me Cleaning the solution worked on .NET.Compilers v2.7 (Visual Studio 2015).

eLGi
  • 80
  • 2
  • 10
1

downgrade "Microsoft.Net.Compilers" from v2.9.0 to v2.4.0 works like a charm

1

I was able to resolve my issue altogether by removing the NuGet package "Microsoft.Net.Compilers", rather than downgrade to 2.4.0.

(For quite some time, the Publish error would disappear if I simply restarted VS, but eventually that stopped working.)

zanussi
  • 1,286
  • 2
  • 22
  • 29
1

First, select the mode (Debug or Release). Then right click on the solution/project then select Clean. Then choose Rebuild. Then Publish.

Jin Ginusuke
  • 67
  • 1
  • 1
  • 11
0

This just happened to me, it turned out to be a simple case of using an int in a ViewComponent call from a razor template, when that argument should have been a Guid. For some reason Intellisense didn't pick it up, I had to turn on detailed verbosity to see the error in the build process.

jmdon
  • 997
  • 9
  • 17
0

I had this problem in Asp.net Core 2 MVC 2.1 So there was no Microsoft.Net.Compilers in my solution. I tried to rebuild all projects, unload / load again but there was no change.

1) So, I have upgraded VS 2017 15.7.3 to 15.8.7
2) Then deleted all bin/release directory contents from each projects in solution.
3) Then deleted all obj directory contents from each projects in solution.
4) Then rebuilded all projects one by one.
Then tried to publish and it succeded.

Maybe if I tried from step 2 in old Visual Studio it would be succed.

Omer Faruk KAYA
  • 342
  • 2
  • 10
0

Try opening the solution with Visual Studio 2017

I had been building and publishing from Visual Studio 2015, as that is the version of Visual Studio that the Version Selector picked when I opened the solution file.

I tried opening my solution file from Visual Studio 2017 instead, and that succeeded in publishing.

Nacht
  • 3,342
  • 4
  • 26
  • 41
0

I had switched to C# 7.3 in Properties > Build > Advanced, but accidentally only did so for the Debug configuration. When publishing (using Release configuration) it was still using C# 7.0, which lacked some of the language features I had used.

Errors weren't visible in the Error List pane, only in the Output pane.

Setting the language version to C# 7.3 for "All Configurations" solved it for me.

This was using current version of Visual Studio 2017, Microsoft.Net.Compilers package not included in project.

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72
0

Try removing the Microsoft.Net.Compilers Nuget package.

I had tried a lot of things, none successful. I did this and the publishing succeeded. To be sure, I restored my project from BitBucket to its original condition, tested to see the publishing failed, removed the nuget package again, and it worked.

Matt Thomas
  • 5,279
  • 4
  • 27
  • 59
0

I had a similar problem. The project was building okay but when I published it Azure send me errors.

My project target .NET framework was 4.6.2 version and I was upgrading Nugget packages, unfortunatelly I upgraded my .NET Compilers to last version and it wasnt compatible to my target .NET version.You should be able to see it here:

Description of .NET Compilers

My target framework

I fixed it by downgrading .NET Compilers to a version compatible to my .NET Framework (In my case, to use 4.6.2 framework I need to use .NET Compiller 2.10).

0

I had similar problem with project using:

  1. .NET 4.7.2
  2. MVC5 solution
  3. All unit test files with file name format: Tests.cs like "HomeControllerTest.cs"
  4. Microsoft Visual Studio Enterprise 2019, Version 16.6.4

For that project, the following Azure DevOps Pipeline settings works:

MSBuild arguments:

/t:Publish;Build /p:PublishDir="$(build.artifactstagingdirectory)\" /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\"

Visual Studio Test Platform Installer: Latest stable

Select test using: Test assemblies

Testfiles:
*Tests.dll
!**\obj*

Searchfolder:$(System.DefaultWorkingDirectory)

Test results folder: $(Agent.TempDirectory)\TestResults

Test platform version: Installed by Tools Installer

Other console options: /Framework:Framework45 /Diag:log.txt /Logger:console

Build platform: $(BuildPlatform)

Build configuration: $(BuildConfiguration)

=== YAML

steps:

  • task: VSBuild@1 displayName: 'Build solution ***.sln' inputs: solution: '$(Parameters.solution)' msbuildArgs: '/t:Publish;Build /p:PublishDir="$(build.artifactstagingdirectory)\" /p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:PackageLocation="$(build.artifactstagingdirectory)\" ' platform: '$(BuildPlatform)' configuration: '$(BuildConfiguration)' clean: true maximumCpuCount: true restoreNugetPackages: true createLogFile: true

steps:

  • task: VisualStudioTestPlatformInstaller@1 displayName: 'Visual Studio Test Platform Installer' inputs: versionSelector: latestStable

steps:

  • task: VSTest@2 displayName: 'VsTest - testAssemblies' inputs: testAssemblyVer2: | *Tests.dll !**\obj* vsTestVersion: toolsInstaller otherConsoleOptions: '/Framework:Framework45 /Diag:log.txt /Logger:console' platform: '$(BuildPlatform)' configuration: '$(BuildConfiguration)' diagnosticsEnabled: true

steps:

  • task: PublishTestResults@2 displayName: 'Publish Test Results **/TEST-*.xml' inputs: testResultsFormat: VSTest
PeterE
  • 1
  • 1