dotnet publish command not working with asp dotnet project in aws buildspecs.yml file - asp.net

I have created sample dot net application, folder structure as follows.
When i am using this command
dotnet publish -c release -o ./build_output demorepo2.csproj build output is getting created inside build_output folder correctly.
Now i have another asp.net mvc web application.
Now i am using same command dotnet publish -c release -o ./build_output test1.csproj but this not working. Getting the following error.
Any idea why this error?

From ASP.NET Web Deployment using Visual Studio: Command Line Deployment
Try to run this command:
msbuild demorepo2.csproj /p:DeployOnBuild=true /p:PublishProfile=MyPublishProfile

Related

Jenkins Dotnet Project Publishing Issue

I am trying to publish my dotnet project-api from jenkins via powershell. The problem is when I publish it from powershell it's missing around 30 files and I can't reach api. However when I publish it from visual studio manually (or from visual studio package manager console with commands) it works perfectly. What might be causing this issue?
Here are the commands that I am running to publish api ;
dotnet restore
dotnet build --configuration release
dotnet publish -c release --output "path to the publish file"
I have also tried with this to publish command yet it didn'T work;
dotnet publish dotnet publish -c Release --self-contained -r win10-x64
I have been trying to figure this issue for a long time but I couldn't find a way. I would highly appreciate any help. Thanks!!
You should try following 2 Execute Windows batch command
Command
"C:\Program Files\dotnet\dotnet.exe" restore yourProjectSLN file
[E.g:yourProjectSLN = git/FolderName/ProjectName.sln , it should be same as jenkins configuration]
Command
dotnet publish yourProject_csproj_file_location -c:Release
[E.g:yourProject_csproj_file_location = git\FolderName\ProjectName.csproj]

dotnet command for creating startup project

I want know what is the command line for making a directory a startup project.
I have 2 directories inside EmployeeManagement and on sln file:
Models
Web
Employeemanagement.sln
Now instead of Right clicking and making Web the startup project, is there a way of doing it using command line interface.
Thanks for your help.
In the .Net 5.0, you can do: dotnet run --project , everytime you need to run the project.
CLI Example:
dotnet run --project Web/Web.csproj

dotnet publish command is not creating zip file for C# library

In visual studio solution I have single .net core 2.0 library project. And to the publish the library i am using dotnet publish -c release command
however its not zipping the publish folder. I have read the issue 6598 and use the suggested approach using dotnet build command as below
dotnet build ApiRouting.sln /nologo /p:PublishProfile=Release /p:PackageLocation="C:\temp\Routing\package" /p:OutDir="C:\temp\Routing\out" /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /maxcpucount:1 /p:platform="Any CPU" /p:configuration="Release" /p:DesktopBuildPackageLocation="C:\temp\Routing\package\package.zip"
`
but that did not work either.
My project is aws lambda project which is C# library project not asp.net web project so i tried removing /p:WebPublishMethod=Package option but that did not work either.
Questions
1>What parameters i need to pass to publish command so that it would create zip file of publish folder.
2>In linked issue 6598 why its suggested to use build command instead of publish when build command only builds the project?
(on side note i can use aws tools for visual studio and use Publish to AWS Lambda and it creates zip file and deploys it to AWS directly from visual studio. However, we are using Jenkins for CI so i want use dotnet cli to create zip file so jenkins can execute that command and create zip file.)
i found it. These 2 links helped me
https://docs.aws.amazon.com/lambda/latest/dg/lambda-dotnet-how-to-create-deployment-package.html
https://docs.aws.amazon.com/lambda/latest/dg/lambda-dotnet-coreclr-deployment-package.html
first installed Amazon.Lambda.Tools
dotnet tool install -g Amazon.Lambda.Tools
and then to package and deploy
dotnet lambda deploy-function apirouting –-function-role myrole --profile lambdadep --profile-location C:\test\testawsprofile

"No executable found matching command" .net core console application

After publishing my .net core 2.0 console application...
dotnet publish src\myapp.console --output C:\publish\console --configuration Release
I try executing in this in the published folder
dotnet myapp.console
but I get the error
No executable found matching command "dotnet-myapp.console"
The trick is to include the full file name with .dll
ie:
dotnet myapp.console.dll

Publishing a dotnet application that's already running

I'm attempting to create a script to simplify the process of publishing a .NET Core website. I'm running into an issue when I run dotnet publish against an already running server. The server is IIS with the dotnet bundle installed, so IIS uses its app pool to start dotnet.
Here's my batch file. I'm happy to use another script type:
cd src/app
dotnet build --no-incremental
dotnet publish --framework netcoreapp1.0 --configuration Release --output ../../dist
When I run the script I get this error:
"The process cannot access the file 'C:\inetpub\wwwroot\app\dist\app.dll' because it is being used by another process."
This makes sense, it appears I need to stop, deploy, and restart dotnet. Can I do this from the script? Or is my approach to this problem wrong?
The best way is to drop an app_offline.htm file to your application folder. This will make IIS stop your application and serve the contents of the app_offline.htm file to the user while you are copying the new version. Once you complete copying the new version of your application remove the app_offline.htm file and IIS will start your application.
You can find more details on running ASP.NET Core applications with IIS in my post.
Based on Pawel's answer, I have a deploy folder containing my app_offline.html file and multiple deploy scripts to IIS. Here's a sample script I use to deploy:
copy .\app_offline.htm C:\hosting\my-project\app_offline.htm
dotnet publish ../MyProject.csproj -r win-x64 -f netcoreapp2.1 --self-contained -c Release -o C:\hosting\my-project
del C:\hosting\my-project\app_offline.htm
I think this is a valid solution, but doesn't help when I want to script the build process.
Stop-Website "xxx"
Stop-WebAppPool "xxx"
Start-Sleep -Seconds 5
dotnet publish --output d:\publocation
Stop-WebAppPool "xxx"
Start-Website "xxx"
if you've created a published profile in Visual Studio and you're using IIS, then you can use that profile instead of writing directly to the destination directory:
dotnet publish /p:PublishProfile=Properties\PublishProfiles\IISProfile.pubxml

Resources