MSB4018 The "RazorGenerate" task failed unexpectedly - asp.net-core

I have updated my visual studio 2019 to latest version with .net 5
after that any project with .net core 2.2 gives this error
Error MSB4018 The "RazorGenerate" task failed unexpectedly.
System.InvalidOperationException: DOTNET_HOST_PATH is not set
at Microsoft.AspNetCore.Razor.Tasks.DotNetToolTask.get_DotNetPath()
After one day try to run the project i find out
that you have to install from huget
PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0"
to solve the problem

After one day try to run the project i find out that you have to install from nuget PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0" to solve the problem

This is something issue with VS. for me I have added 'DOTNET_HOST_PATH' path with
%ProgramFiles%\dotnet\dotnet.exe . and restarted . problem solevd

Related

MSBuild Error task show up as a warning in VS

I have an Error task in a C# MSBuild project. The error shows up as a warning in VS2022, below a huge number of other errors that are directly caused by the Error task halting the build. I'd prefer that the other errors don't show up at all, but failing that, the Error task error should at least be on the top of the list and certainly not a mere warning. How can I fix this?
The Error task looks like this:
<Target Name="ShowError">
<Error Text="ToErrIsHuman" Code="CS0518"/>
</Target>
The Project has InitialTargets="ShowError" to trigger the Error task. The Code attribute does not seem to have any effect.
Error shows up in 4.x .NET Framework projects. Restart Visual Studio to fix.

Failure writing debug information: Unable to load DLL 'Microsoft.DiaSymReader.Native.amd64.dll'

I installed a VS2017, tried to develop a first app in VS2017.
File > New Project > Visual Basic > Windows Desktop > Windows Forms App (.NET Framework)
simply tried to run an app with only one label on form, but build error comes up, I clicked on "Yes" then dialogue box appears (image).
Error Code- BC37225
Error Message- Failure writing debug information: Unable to load DLL <br>'Microsoft.DiaSymReader.Native.amd64.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Then searched SO, read and tried solutions, but not worked.
What I tried from SO is-
Error while building C# Console Application: Error CS0041 Cannot find a module
(1) installed Microsoft.NETCore.Platforms (nuget package)
(2) installed Microsoft.DiaSymReader.Native.amd64.dll (nuget package)
(3) Unable to load DLL 'Microsoft.DiaSymReader.Native.amd64.dll
in this, solution is available (accepted answer), but I don't know from where to delete these lines of code.
<PropertyGroup>
<Deterministic> true </Deterministic>
</PropertyGroup>
what could be the solution?
When the build errors dialog comes up it asks if you want to run a previous build because the current build will not compile (won't make a new .exe file) Since this is the first run of your program there was no previous build, no .exe. What you need to resolve are the build errors.

The "TransformWebConfig" task failed unexpectedly - System.Exception: The acceptable value for AspNetCoreModuleHostingModel property is either

I get
'The "TransformWebConfig" task failed unexpectedly. System.Exception: The acceptable value for AspNetCoreModuleHostingModel property is either "InProcess" or "OutOfProcess".'
error while publishing an ASP.NET Core 2.2.0 application (actually it is the included sample application) for win-x64 environment. Both Visual Studio 2017 and 2019 gives the same error. I am working on Windows 10. What should I do to solve this?
Last part of publish Output is:
c:\users\engin\source\repos\NetCoreWebApplication2\NetCoreWebApplication2\obj\Release\netcoreapp2.2\win-x64\PubTmp\Out\
C:\Program Files\dotnet\sdk\2.2.200-preview-009648\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(49,5): Hata MSB4018: "TransformWebConfig" görevi beklenmedik biçimde başarısız oldu.
System.Exception: The acceptable value for AspNetCoreModuleHostingModel
property is either "InProcess" or "OutOfProcess".
konum: Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.TransformAspNetCore(XElement aspNetCoreElement, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel)
konum: Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.Transform(XDocument webConfig, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel, String environmentName)
konum: Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute()
konum: Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
konum: Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
2 Derleme başarısız oldu. Daha fazla ayrıntı için çıktı penceresini denetleyin.
========== Oluşturma: 1 başarılı, 0 başarısız, 0 güncel, 0 atlandı ==========
========== Yayın: 0 başarılı, 1 başarısız, 0 atlandı ==========
I would suggest disabling web.config transforms altogether. In an ASP.Net Core project you probably do not need to transform web.configs since supplying environment variables is handled by convention with appsettings.[Environment].json files.
From the docs at https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2:
To prevent the Web SDK from transforming the web.config file, use the <IsTransformWebConfigDisabled> property in the .csproj file:
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
I had the same problem and found the solution
In the csproj file, find following line and delete.
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
Had the same issue on .net core 2.2.104. Update the section to this:
<AspNetCoreHostingModelV2>InProcess</AspNetCoreHostingModelV2>
Note the V2 addition.
The answer #Barış Bar provided is working but can cause future errors. There is a bug about UpperCases. Just change InProcess in csproj file with lowercase
<AspNetCoreHostingModel>inprocess</AspNetCoreHostingModel>
It is said that the bug will be corrected in VS 2019.
InProcess or OutOfProcess
Just add this line to your web.config file
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
For me, there was a permission issue which is why, while publishing, a transformation task was running on web.config file. That file did not had access for normal user.
Closing Visual Studio and running it as Administrator then publishing the project worked for me or you can try on setting the correct permissions for the problematic file.
After successfully publishing the project once with administrator privileges, visual studio started working with normal users as well (weird though but good).
UPDATE:
Stumbled into the same problem again, and this time it was not resolved by the above solution, I had to check back the project directory and some of the files were marked Read-Only had to change it to get it working. I suppose this is a problem with the TFS which gets the files and sets them as Read-Only.
My .NET Core 2.2 application build was failing on Jenkins but it was working fine on local machine.
Error: error MSB4018: The "TransformWebConfig" task failed unexpectedly.
Fix: Removed below line from .csproj file
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
I had a project in TFS, due to some issues, the TFS went down and when I made it go online again, it failed to publish the project, while the debugging worked fine. It caused the error (The TransformWebConfig task failed unexpectedly).
After checking the output window, it seemed some files were not accessible to visual studio, or were protected. So, it was because of the TFS, all or most of the files in the project were set as Read-Only which is why Visual Studio couldn't transform those files.
Removing the Read-Only flag from the project fixed the publishing problem.
find the project file (.csproj) and update this code
<AspNetCoreHostingModel>OutProcess</AspNetCoreHostingModel>
to this
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
Adding this to the .csproj file did it for me:
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
If you are upgrading your .net core version from 3.1 to higher framework, please check web.config aspNetCore node
The attribute hostingModel should be inprocess (all small case) vs InProcess in .netcore 3.1 framework
This change worked for me and able to publish my project.

MSBuild 15: The "Error" task could not be instantiated

I'm attempting to programmatically build a project which uses C#7, and therefore MSBuild 15, but this task is failing seemingly because of mismatched assembly references.
Here is my code:
string projectFilePath = Path.Combine(args.Any() ? args.First() :#"C:\Users\newsoni\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2.sln");
ProjectCollection pc = new ProjectCollection();
Dictionary<string, string> globalProperty = new Dictionary<string, string>();
globalProperty.Add("Configuration", "Debug");
globalProperty.Add("Platform", "x86");
BuildParameters bp = new BuildParameters(pc);
bp.Loggers = new ILogger[] { new Logger(), new ConsoleLogger(), };
BuildRequestData BuidlRequest = new BuildRequestData(projectFilePath, globalProperty, "4.0", new string[] { "Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(bp, BuidlRequest);
Here is the error message:
C:\Users\newsoni\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2.sln.metaproj : error MSB4127: The "Error" task could not be instantiated from the assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Build.Tasks.Error' to type 'Microsoft.Build.Framework.ITask'.
C:\Users\newsoni\Documents\Visual Studio 2017\Projects\ConsoleApp2\ConsoleApp2.sln.metaproj : error MSB4060: The "Error" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
Here is a link to a project you can use to recreate the issue:
https://drive.google.com/a/xibis.com/file/d/0B-mqMIMqm_XHcVRJQmtxQkd1b3c/view?usp=sharing
You will have to change the path in the code to a project on your own machine, but it doesn't seem to matter if this is a VS 2017 project or earlier.
One other thing that may or may not be relevant, I noticed that the Microsoft.WebApplication.Build.Tasks.Dll in this folder:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications
Still seems to be referencing Microsoft.Build.Framework.dll version 14, not 15 as I would have expected.
It turns out there are two issues in my test project. The first is due to the naming of the project.
However there is a second issue which is due to the references not being correct. To use MSBuild 15 programmtically you must install the following packages:
Install-Package Microsoft.Build -Version 15.1.1012
Install-Package Microsoft.Build.Framework -Version 15.1.1012
Install-Package Microsoft.Build.Tasks.Core -Version 15.1.1012
Install-Package Microsoft.Build.Utilities.Core -Version 15.1.1012
Install-Package Microsoft.Net.Compilers -Version 2.2.0
There is one more step which is nuts and completely undiscoverable. You must now add a reference to this DLL which should be relative to your solution folder:
packages\Microsoft.Net.Compilers.2.2.0\tools\Microsoft.Build.Tasks.CodeAnalysis.dll
I opened a support ticket with Microsoft and they have confirmed that this is a bug in Visual Studio 2017.
They are aiming to get a fix for this into update 3 for Visual Studio, but this may slip.
This issue tracks the bug:
https://github.com/Microsoft/msbuild/issues/2194
There is no workaround at present for this API, but you can invoke the MSBuild exe using Process as an alternative.
If you have MSBuild installed on your PC, either directly or through Visual Studio, the proper fix is to use the package Microsoft.Build.Locator which will find that installed version and execute the build using it.
Install these packages
Microsoft.Build
Microsoft.Build.Framework
Microsoft.Build.Locator
The first 2 are needed so that the code can compile but should be excluded from the project output.
In your application startup add the following line of code, this only has to run once.
Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();
Remove any additional binding redirects in your app.config that are specific to Microsoft.Build or other build libraries. The call to the Microsoft.Build.Locator assembly will ensure that these redirects take place automatically.
References
Update an existing application for MSBuild 15
Github MSBuildLocator.

Unable to build project output group 'Content Files from Web (Active)

I got below error in MS build.
WARNING: Could not find prerequisite 'Microsoft .NET Framework 4 (x86 and x64)' in path 'C:....\Microsoft SDKs\Windows\v7.0A\Bootstrapper\'
ERROR: Unable to build project output group 'Content Files from Web (Active)'
Any suggestions
Thanks
This error came up because my workspace wasn't upto date. I did get force (Get specific version) and rerun the build, it worked !! Posting it may helpful to somebody else.
In your project expand all the Folders and see if there are any files missing with yellow alert symbol.If you delete them,you can build your application as normally.