Build failed. Check the Output window for more details - C# publishing fails but build succeeds
Asked Answered
S

19

20

I am trying to publish a web application on Visual Studio 2017. The build succeeds but the publishing fails. When it fails an error dialog comes up which says "Publish has encountered an error. Build Failed. A diagnostic log has been written to the following location: .."

This is what the file with the log contains:

System.AggregateException: One or more errors occurred. ---> System.Exception: Build failed. Check the Output window for more details. --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at Microsoft.VisualStudio.Web.Publish.PublishService.VsWebProjectPublish.<>c__DisplayClass41_0.<PublishAsync>b__2() at System.Threading.Tasks.Task``1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.ApplicationCapabilities.Publish.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__116.MoveNext() ---> (Inner Exception #0) System.Exception: Build failed. Check the Output window for more details.

I've tried running the application as Admin but it still doesn't work. I also searched for the Microsoft.Net.Compilers reference but it's not in my project.

Saturate answered 27/7, 2018 at 22:1 Comment(2)
What does the errors section of vs say? Could it be that you changed your app target framework version but the publish profile destination location is wrong?Guadalupe
@EdwardChopuryan The error section says nothing at all. And no I haven't changed the target framework. What do you mean by the publish profile destination location is wrong? Can't I publish to any location?Saturate
P
20

Make sure Build + Intellisense is selected, not just Build Only. That way you can see other errors that might be hiding out there.

enter image description here

Pagano answered 22/10, 2019 at 20:22 Comment(0)
C
13

Try open visual studio as admin.

Cloudscape answered 25/2, 2021 at 20:22 Comment(0)
A
6

Please provide the read write permission for iuser. The folder in which you are publishing by right click on folder > Properties > Security tab

Alfy answered 1/12, 2018 at 8:15 Comment(0)
D
4

This is because of admin rights , Open the solution in administration mode in the visual studio and publish the solution it will work and make sure that published folder has read write access .

Drugget answered 20/8, 2019 at 13:59 Comment(1)
Make your answer more expressive and with example.Ellora
P
4

If you have opened vs with admin rights and if you publishing folder has all the read/ write permission you probably need to remove the missing reference from .csproj file

  1. unload your project
  2. right click edit .csproj
  3. remove all the included files that are no longer referenced/used by your current project
  4. re-load your project
  5. try to publish again...
Pretorius answered 20/12, 2020 at 12:55 Comment(1)
I had a similar problem in .NET 6, I had added a project twice in ItemGroup TagSelfrespect
I
2

This is user11952046's answer (which I saw after making numerous trials with VS) with more details.

I have stumbled across the same error after realizing that my publish profile was using .NET Core 3.0 as target framework instead of 3.1 (all assemblies were targeting 3.1). Not sure that it is related, but I have also moved the db context + migrations from the main assembly (that contains Startup.cs).

My development environment is VS2019.

  1. Double-checked that publish works on Local IIS. That required elevating the VS 2019 (admin).

  2. While being elevated I have published on target Web server (IIS) and it worked as expected.

  3. Closed and restarted without elevation and published again and it worked.

I am not sure what happened, but I guess that publish had a one-time requirement to change some file that needed elevation.

tl;dr - make at least one publish using VS2019 started as Admin and then you can publishes using non-admin mode.

Invade answered 1/2, 2020 at 16:9 Comment(1)
This worked for me - published many times before, but then tried to publish some insignificant code update to local IIS and got the error. "one publish using VS2019 started as Admin" is the answer VS2019 16.4.5 .NET Core 3.1 Web API with Angular SPANest
T
2

I have upgraded project framework form 4.0 to 4.7.2 had same issue when trying to publish service, resolved by adding following tags in .cproj file of project

Unload Project >> Edit Project file

Update ToolsVersion="15.0" in following line

<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

then add following line after above line

 <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />


      <PropertyGroup>   
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>  
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> 
  </PropertyGroup>

add above before following line

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

add following line after above

   <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false"/>

this solution worked for me able to publish wcf project after upgrading framework from 4.0 to 4.7.2

Toed answered 22/5, 2020 at 5:40 Comment(0)
M
1

I faced the same "Build Failed" problem.

All I did to fix it was to enable AppDbContext under Entity Framework Migrations and provide connection string

screenshot

Murk answered 16/6, 2020 at 10:55 Comment(0)
C
0

Disabling Resharper fixed the issue for me!!!

Here is how to disable it How can I disable ReSharper in Visual Studio and enable it again?

Also some blogs claim updating MSBILD tools will fix the issue. For me just disabling Resharper worked.

Download the latest version of MSBUILD tools from https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017, run it, choose Modify and then select “Web development build tools” and “.NET Core build tools”.

Contractive answered 8/11, 2019 at 15:28 Comment(2)
The links are helpful, but its preferred to also include the solution in the posting. As you know, all links eventually die..Lebna
@Lebna that's true! You can disable ReSharper 5 and newer versions by using the Suspend button in menu Tools -> Options -> ReSharper.Contractive
B
0

I faced a similar problem in which I could run my project in debug mode but I whenever I wanted to publish I faced the Build failed problem.

I think this will help someone facing the same issue

If your project path is long try to move the project to a shorter path. Here is an example, change project path from C:\Users\xxxx\xxxx\xxxx\project1 to C:\Users\xxxx\project1

Borglum answered 13/1, 2020 at 14:43 Comment(1)
Worked for me, I moved my project and Publish Location in shortest possible path(s)Graphophone
H
0

This more likely because you do not have full right control for that particular folder you are trying to publish steps: 1)right click on folder you are trying to publish 2)go to security 3) click on edit and add your current user login like (domain\username) 4)click on the checkbox on full control and save it 5)then try to publish

enter image description here

Henbane answered 14/3, 2020 at 13:48 Comment(1)
Hi, please don't post images or links in an answer, as they may be removed by their hoster, breaking the answer. You may explain a bit more your solution. Please refer to stackoverflow.com/help/how-to-answer to learn how to write a "good" answerFortunetelling
P
0

I had the same issue, when publishing got the error :

System.AggregateException: One or more errors occurred. 
---> System.Exception: Build failed. Check the Output window for more details.
   --- End of inner exception stack trace ------> (Inner Exception #0)"

Solution : in file explorer the share drive target of the publication was disconnected. After reconnecting the drive the error disappeared and publication went ahead.

Pasco answered 19/6, 2020 at 15:48 Comment(0)
S
0

I solved same issue removing a folder ("node_modules") from my project. Inside this folder path was too long

Stebbins answered 26/10, 2021 at 7:53 Comment(0)
G
0

change in .sln file and give project folder name

like this

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Index", "Index.csproj", "{4F3980BF-6DE6-7FDD2256A8B3}"

"Index" is project folder name.

Grote answered 23/3, 2023 at 17:58 Comment(0)
P
0

Just had this issue and managed to fix it by signing out of my profile and signing back in, restoring credentials. I then was presented a popup to trust the site certificate which apparantly was no longer valid (DEV environement). After I could publish again.

Posting this because none of the answers above applied to or helped me.

Prato answered 25/5, 2023 at 9:33 Comment(0)
P
-1

Download LastVersion of MSBUILD Tools. Build your Project and select Build + IntelliSense in Error List and show message Error if exist . and Download System.Reflection.Emit from Nuget try again publish your project.

Prepotency answered 23/12, 2019 at 7:24 Comment(0)
B
-1

Take a look at FolderProfile.pubxml file located in YourProject\Properties\PublishProfiles and make sure term is configured with correct version.

Brimful answered 28/12, 2019 at 11:45 Comment(0)
H
-1

There are many causes for this problem. I already had the IIS web site configured, as well as the right permissions for the user. Obviously the project built successfully on my local machine. The problem was I added the absolute windows path on 'Site path' section in VS publish profile. Leave this empty!

Hushhush answered 16/2, 2020 at 11:18 Comment(0)
E
-2

I faced the same issue while trying to publish to an Azure App Service. For me, closing Fiddler solved the problem.

Equivalent answered 23/2, 2020 at 23:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.