"The directory name /app/Views/ is invalid" on ASP.NET Core deployment using docker - linux

I followed this article to setup a performant ASP.NET Core deployment using Docker. This works until I try to start the container using docker run which calls dotnet MyAppName.dll There I got an exception, that the View path is not existing:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: The directory name /app/Views/ is invalid.
And thats true, cause in the folder created by dotnet publish area only dll files and no View folder:
user#server:/etc/jenkins/workspace/App# ll publish-output | grep View
-rwxr--r-- 1 root root 237K Aug 31 19:26 Microsoft.AspNetCore.Mvc.ViewFeatures.dll
I cant understand this, cause the View folder is included in the publishOptions like wwwroot too, which is also missing:
"publishOptions": {
"include": [
"wwwroot",
"Views/**/*.cshtml",
"Areas/**/*.cshtml"
]
},
I also tried "Views" instead of "Views/**/*.cshtml" but not working. In my understanding, those publishOptions should result in copying those folders to the publishing-directory when using dotnet publish.
What am I doing wrong?
I'm using the microsoft/aspnetcore-build:1.0.1 image for building and microsoft/aspnetcore:1.0.1 for starting the app like recommended as best practice in the article.
UPDATE
Seems to be a problem on linux only. My Win10 development machine works fine, there I get any view-folders published from the main app and areas as expected.
UPDATE #2 Using the examples on the aspnetcore-build repo on the docker hub, its not working too.
UPDATE #3 I created a new ASP.NET Core MVC project on my Windows 10 development machine using Visual Studio, then transferred it to the linux box: Not working, the views are missing.
UPDATE #4 Created a new app using dotnet new -t web directly on the linux box: Works like expected!
UPDATE #5 I ran dotnet new -t web on the Windows machine, moved the created folder to the linux server: Not working - Strange...

The problem was a missing space in the documentation before the dot, which should refer the current folder.
Wrong (1:1 copy from the description of the docker image)
RUN dotnet publish --output /out/. --configuration Release
Correct
RUN dotnet publish --output /out/ . --configuration Release
Here is the space missing: --output /out/{Space}.

Related

Azure Devops release to IIS fails after AOT blazor wasm

I have a .NET 7.0 blazor wasm app, that I deploy to a windows server running IIS. This has worked fine, until i added the following to my project (The client, and the project is .net core hosted):
<WasmEnableSIMD>true</WasmEnableSIMD>
<RunAOTCompilation>true</RunAOTCompilation>
First i got the following error in my build pipeline:
error NETSDK1147: To install these workloads, run the following command: dotnet workload restore
So i added a command line step to my build pipeline where i run the following command:
dotnet workload restore
So far so good. Now the project builds again. But my release now fails. I have 3 steps in my release pipeline for my IIS server:
Stop app pool
deploy my app
start my app pool
This worked fine before adding the two statements above. But now i get the following error:
Failed to deploy web package to IIS website.
Error: Unrecognized argument 'Files\IIS\Microsoft'. All arguments must begin with "-".
Error count: 1.
Error: The process 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' failed
with exit code 4294967295
I can't seem to find a solution, so has anyone tried something similar?
Apparently i wasn't the only one with the issue:
https://github.com/microsoft/azure-pipelines-tasks/issues/17634
I ended up removing web deploy 4.0, and now it works again.
Maybe if I had waited longer, i wouldn't have to remove web deploy 4.0

GenerateEFSQLScripts fails when trying to publish to IIS using Web Deploy from TeamCity

Running into a total dead-end here.
I've created a Publish Profile for a .net6 application that we want to publish to IIS with Web Deploy. In the Entity Framework Migration section, the option to "Apply this migration on publish" is selected.
When manually clicking publish, everything works. However, we want to automate this in TeamCity using the .NET build runner. The publish step fails at:
Generating Entity Framework SQL Scripts...
Executing command: dotnet ef migrations script --no-build --idempotent --configuration Release --output "C:\TeamCity\buildAgent\work\cbf95cc2b4413601\MySolution.Api\obj\Release\net6.0\PubTmp\EFSQLScripts\MySolution.Data.MyContext.sql" --context MySolution.Data.MyContext
C:\Program Files\dotnet\sdk\6.0.400\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(221,5): error : Entity Framework SQL Script generation failed
Internal error message details: BuildMessage1 0 Text DefaultMessage ERROR 400682522803500 tags:'tc:parseServiceMessagesInside'
Error message is logged
Build FAILED.
I cannot find any specific error messages anywhere in any log. Looking in the Microsoft.NET.Sdk.Publish.TransformFiles.targets file shows that it's failing on GenerateEFSQLScripts - an MSBuild command that executes dotnet ef under the covers.
I thought this might be a case of dotnet ef not being installed on the build agent. But when I manually run the command myself from C:\TeamCity\buildAgent\work\cbf95cc2b4413601\MySolution.Api, it succeeds, and the SQL scripts are successfully created.
I also thought it might just be a case of the command being run in the wrong directory (i.e. in the root MySolution folder rather than the MySolution.Api folder), but explicitly setting the working directly fails at the same point, with the same error.
Has anyone seen this before? Or could point me to where an actual error might be located?

Error - Access is denied - deployment to Azure App Services

We use automatic deployment process in Azure by KUDU scripts and by today we see strange error in Azure deployment center:
Command dotnet publish (and also 'dotnet build') returns:
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
Unhandled exception. System.ComponentModel.Win32Exception (5): Access is denied.
System.ComponentModel.Win32Exception (5): Access is denied.
at System.Diagnostics.Process.set_PriorityClassCore(ProcessPriorityClass value)
at System.Diagnostics.Process.set_PriorityClass(ProcessPriorityClass value)
at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
at Microsoft.Build.CommandLine.MSBuildApp.Main(String[] args)
at System.Diagnostics.Process.set_PriorityClassCore(ProcessPriorityClass value)
at System.Diagnostics.Process.set_PriorityClass(ProcessPriorityClass value)
at Microsoft.Build.CommandLine.MSBuildApp.Execute(String[] commandLine)
Failed exitCode=-532462766, command=dotnet publish "D:\home\site\repository\
...
Details:
there is automatic deployment process by KUDU script
app is .NET Core application, .csproj has target framework: netcoreapp2.2
Issue probably will be on Azure side, because we did't do any bigger change in the project.
Has anybody same/similar issue?
We had the same issue and after investigation we found that:
Azure applied new 'dotnet' version 3.1.301 and this version of SDK throws that error (your version you can check by commnad 'dotnet --version')
by command 'dotnet --list-sdks' you can see all installed SDKs
then we simple used previous version (in our case v3.1.202)
the easiest way how to tell exact version of dotnet sdk is by global.json
Example:
global.json
{
"sdk": {
"version": "3.1.202"
}
}
And file must be in 'working directory', and KUDU script has working directory here D:\home\site\repository
When your deployment was OK on previous version of dotnet SDK, than this should definitely help.
This problem could also happen in other situations because of the sdk is installed as admin (e.g if installed with sudo).
In this case uninstalling the sdk and installing it as non-admin user could help resolve the issue. You can use this script to install for non-admin user.
e.g (tested on ubuntu 20.04):
$ wget https://dot.net/v1/dotnet-install.sh
$ chmod +x dotnet-install.sh
$ ./dotnet-install.sh -c Current
Add to the path and verify:
$ echo "export PATH=$HOME/.dotnet:$PATH" >> ~/.bashrc
$ exec bash
$ dotnet --version
3.1.402
NB: After doing this you may get an error error : Unable to obtain lock file access on '/tmp/NuGetScratch/lock then you could remove it and good to go.
sudo rm -r /tmp/NuGet*

Site cannot be loaded when using Deploy to Web app from VS Code

At work I'm using Visual Studios 2019 to publish my ASP.Net Core 2.1 App to the Azure App Service. At home I run a linux maschine and use VS Code to work on the project. Now I'm having trouble to deploy the app to Azure using 'Deploy to Web App' in VS Code. The process finishes successfully but when I open the url I get an 'IIS 502.5 Error - Process Failure'. Using Visual Studio this does not happen.
Before deploying the app I tried to build it using
dotnet build -c Release
with no success. I also tried
dotnet publish -c Release -f netcoreapp2.1 --no-self-contained
with no success too. Both commands followed by 'Deploy to Web App'.
Am I doing something wrong or do I miss some build-option?
Got it myself. Found the solution here.
You just have to set the deploySubpath to the directory where dotnet publish puts the generated files. In my case I had to set it to project_1/bin/Release/netcoreapp2.1/publish, which will be created by the command dotnet publish -c Release.
You can set the deploySubpath value in Settings > Extensions > Azure App Service or by editing the file settings.json in the .vscode directory. This directory will be created in the root directory of your workspace.
Be careful to always set the deploySubpath relatively to your .vscode directory. In my case my workspace looks like this
-- .vscode
:- project_1
`- project_2
where project_1 is my ASP.Net Core project and project_2 is a nodejs project.

Publish .Net Core to IIS - Process cannot access file

I am deploying my ASP .Net Core 2.0 app to my remote server using FTP. Remote Server is using IIS 8. When I publish my app, I get the following error.
Unable to add 'Project.dll' to the Web site. The process cannot access the file because it is being used by another process (550).
I been able to bypass this by manually creating an app_offline.htm first on the publish directory, and then publishing my app via Visual Studio 2017.
I was wondering, is there an easier way of doing this? or is there an easy way I can script this, so that app_offline gets created automatically before publish? and then deleted after publish?
Anyone that's curious, I gave up depending on VS to publish my .NET Core project. I'm now using WinSCP and _PublishToWeb.bat script I created to accomplish the task.
I first created a file called _app.offline.htm on root directory my publish folder. Then when I need to publish, I run the script below.
This script does the following:
1. Builds the .NET Core project to a specific folder, let's call it "_dist" folder.
2. Connects to my ftp server/publish folder and renames "_app_offline.html" to "app_offline.html", so that the server goes offline.
3. Synchronizes _dist folder with publish folder.
4. When done, changes "app_offline.htm" to "_app_offline.html", so the website is restarted.
_PublishToWeb.bat
echo off
echo Publishing to ProjectName (Optional)
set ProjectRemoteFolder=RemoteFolderName
set ConnectionString=ftp://username:password#serverIp:serverPort
set WinSCP="path to WinSCP.com"
set ProjectDistPath="a folder where dotnet publish will build the project to"
set WebAppProject="path of the project. dotnet publish will run here"
rem Build project and put it in to distribution folder
cd %WebAppProject%
dotnet publish -c Release -o %ProjectDistPath%
rem Connect to FTP and synchronize folder
%WinSCP% /command "open %ConnectionString%/%ProjectRemoteFolder%/" "mv _app_offline.htm app_offline.htm" "synchronize remote %ProjectDistPath%" "mv app_offline.htm _app_offline.htm" "exit"
rem pause
I'm sure there are better solutions out there, but this has been working well for me so far.

Resources