How to run compiled blazor web client from command line? - c#

Let's say I have classic blazor projects -- server, client, and shared. I can set server as startup project in VS 2019 and run it (it will run server). Or I can set client as a startup project and run it (it will run client). So far, so good.
I can switch to command line, navigate to "bin" folder of server and execute "dotnet WebBlazor.Server.dll", server will run as I expected it.
But when I navigate to client folder I can see dll is placed in two places -- next to "wwwroot" folder and inside "wwwroot/_framework" folder along with other dlls. When I try to execute "dotnet WebBlazor.Client.dll" (in both mentioned places) I got error stating there is no such file as WebBlazor.Client.deps.json. and also that 'hostpolicy.dll' library is missing.
Futher error message directs me into two choices that I should run web client as self-contained app or framework-dependent app. All I would like to do is to run client -- if I am not mistaken in server case Kestrel is run automatically and on top of tip the server code I write. I assumed this is the case also with the client, so I would like to run it in CLI as VS is able to run it.
I am not publishing my app yet, I just want to run compiled binaries from CLI.

In your client project folder, launch :
dotnet run

Related

In Azure Devops, how can I deploy an exe file to as server as part of release (or something similar)

A solution consists of...:
Web app
Console app ("jobserver", which pulls jobs and processes them)
All is C#, .Net Core 5.
I have continuous deployment set up, so new versions of the web app are deployed to Azure Web App automatically.
However, the console app, I cannot figure out a good way to deploy to a Windows server (or pull). Right now, I go to the server, stop the app if it is not doing anything (otherwise I wait a bit). Then I copy the files over and start it up again. All manually.
I can think of several complicated workarounds, but I am thinking there must be easier way.
What are some ways the deployment of exe file could be handled? How are others handling this?
Ps. The console app cannot run on Azure Web App or as WebJob or similar, because it has requirements that means it has to run on a "real" windows server.
You can use the PowerShell on Target machines or SSH tasks to run commands on a remote machine. Similarly, to copy files, you can use Windows Machine File Copy or Copy Files Over SSH to copy your .exe to the server.

How to electronize an ASP.NET Core hosted Blazor WebAssembly app

I have created a new Blazor WebAssembly project and made it ASP.NET Core hosted (so, Visual Studio created three projects, one for the server, the actual WebAssembly client project, as well as a class library holding types used by both apps). Then, I just followed the documentation at https://github.com/ElectronNET/Electron.NET to electronize the server app. In theory, everything should be fine.
Problems occur when I try to run the app via electronize start. The build fails with the following error.
...Microsoft.NET.ILLink.targets(143,5): error NETSDK1102: Optimizing assemblies for size is not supported for the select
ed publish configuration. Please ensure that you are publishing a self-contained app. ...
Error occurred during dotnet publish: 1
Of course, I can imagine what the actual problem is. The Electron build tries to publish the assemblies for the current target platform, which is x64 in my case, but this is not supported for blazor-wasm projects. What I basically want to achieve is that the client build output gets included with the electronized server app.
Update
The following command successfully builds the electronized app, if the PublishSingleFile and PublishReadyToRun properties are set to false. Though, this is far from optimal since it creates an app that comes with a performance penalty (increased load time).
electronize build /target win /PublishSingleFile false /PublishReadyToRun false
Sadly, the switches currently do not work with the electronize start command.

Appveyor: Running command after deploy on each affected environment

My company has recently switched from automatic migrations on our Entity Framework databases to now relying on a command being run to migrate and afterwards seed the database.
We want this to run on the database of each environment that is being deployed to via Appveyor, so when pushing to a specified branch Appveyor builds, deploys and then runs the migrate and seed command on each environment after the deploy is completed.
We usually place all build and deploy configuration in a yaml file, but there doesn't seem to be any way to run commands after deploy on the environment itself. The yaml script command after_deploy runs command as part of the build process, not the environment.
The Appveyor environment has a setting After deployment command that seems to be the key, but it requires the "runCommand" provider to be allowed on the server side. The reason for this is understandable, but how do I go about setting this up?
The guides I've found haven't really given anything. Nothing applicable on SO, and the link to Microsoft that Appveyor prints as an error in the deploy process is no longer accurate.
Because environment deployments run on shared worker severs, custom scripting is not allowed. But you could try a deployment project approach. This divides your project into a "main project" and "deploymnet project" thus simulating a deployment environment, allowing you to decouple builds and deployments.
Assuming you are deploying to azure, you could then use this script my colleague wrote to run your commands on the server.
If you are not deploying to azure, you could switch to AppVeyor deployment agent which uses web deploy behind the scenes.

How to run DB migrations in console application in team services deploy task?

I'm looking to move an ASP.NET Core application into Visual Studio Team Services for continuous integration and continuous deploy. My application is currently built and deployed "manually":
Build by "publishing" to Web Deploy package in Visual Studio.
Apply DB-migrations (implemented using Simple.Migrations) by running a console application (built along with te web app in step 1) on the target server.
Deploy the built web app using Web Deploy on target server.
And now I would like to automate this process using Visual Studio Team Services. Building the web app (step 1) and deploying it to an Azure App Service (step 3)seems pretty straight forward. But I'm not sure how to apply my Simple.Migrations database migrations (step 2). Is it possible to run a console application (built along side the web app during the build phase) in the deploy phase? A task for running command line scripts certainly exists but I'm not sure what you can actually do with it.
Note that I would like to use the hosted agent (if that makes any difference).
There is a built-in task called: Deploy: PowerShell on Target Machines. This task uses Windows Remote Management (WinRM) to access on-premises physical computers or virtual computers that are domain-joined or workgroup-joined. This task can run both PowerShell scripts and PowerShell-DSC scripts.
Not sure if you could put your console application code in a ps script or directly Run a C# .cs file from a Powershell Script . Another way is using PowerShell run DB migrations. A sample for your reference: Use PowerShell to Migrate SQL Server Instances (db, logins, jobs, etc)

Error CS0006: Application runs locally but not from server

I have an application that is built from a TFS Build server into a drop folder. The application builds with no errors reported. The application is in C# using .NET 4.5.1.
When I copy the deployment folder to my local desktop, the application runs fine.
However, when I copy the deployment folder to our internal server, I get the following error when trying to run:
error CS0006: Metadata file
'file:\NNNNSERVER\YourEXEFolder\log4net.DLL' could not be found
This error is repeated for all DLL's in the project and for the executable itself.
Other applications with similar profiles (C#, .NET 4.5.1) run fine on the same server. It seems to me to be pretty clear that its not the build or the code but something with the server or permissions, but I need to find something to tell our systems people.

Categories