Deploying ASP.NET 5 application with backing DB on client servers - asp.net

I'm writing an ASP.NET 5 application targetting .Net Core using EF7. When I'm done, I'd like to publish the application to a platform-specific installer that, when run, will install a service, deploy a database based on user-input credentials for a SQL Server. The service will self-host the ASP.NET application.
Is this possible? How would I go about achieving this?
Thanks!

We use MSDeploy at work to deploy all of our components: web applications, windows services, scheduled task, SQL databases, etc.
You could use the following command to package up the service code:
msdeploy -verb:sync -source:dirPath=/path/to/service -dest:package=servicePackage.zip -verbose
And this command to deploy it to the target:
msdeploy -verb:sync -source:package=/path/to/service -dest:package=servicePackage.zip -verbose
Use a database project for the SQL database and create a DacPac to publish. You can use MSDeploy to publish the DacPac:
MSDeploy –verb: MSDeploy-verb –source:dbSqlPackage="db.dacpac"[,dbSqlPackage-source-parameters] –dest:dpSqlPackage="TargetConnectionString"[,dbSqlPackage-target-parameters]
Finally use Manifests to wrap it all up into a single MSDeploy package.
Regarding the user input values for the database, I would use WebDeploy Parameterization files to define the variables and apply them to the database deployment. These parameterization files can be used for non-web deployments via MSDeploy. Then write some PowerShell to wrap the MSDeploy command for deployment to prompt the user for their inputs and edit the SetParameters file.

Related

migration from Octopus to TFS 2017 - Publishing ASP.NET web sites

We currently use Octopus Deploy to push web sites to IIS servers hosted on Window Server 2012.
We wish to ditch Octopus and use our on-premises TFS 2017's inbuilt release system instead. We have build definitions that publish artifacts (the web site binaries & content) ready made .
With Octopus we have tentacles installed on all the servers.
The legacy release process defined in Octopus is like so:
Set up IIS (Powershell script to configure app pools for a site, map virtual directory to absolute path)
Deploy nuget package (package contains web site binaries & scripts) - unpacks package containing web site to the physical path of the associated virtual directory
Enable Windows Authentication (one-line powershell script that calls Set-WebConfigurationProperty)
Disable Anon Auth (powershell again.)
I'm not keen on the amount of Powershell used in our Octopus process, and would like to minimise Powershell in the TFS release definition.
My question is: what is the Microsoft recommended way of deploying ASP.NET web sites (vanilla MVC projects, not .NET core) to servers in a CI environment? Is it possible to configure the sites authentication at the same time?
NB:
I took a look at the OOB IIS publishing WinRM deployment tasks and I fear they may require more time than our infrastructure team has (to configure firewalls etc.)
We have Visual Studio 2017 installed on the build server.
TIA,
Scott
According to your description you are deploying on a Web site hosted on IIS.
First through TFS build you could use some msbuild arguments such as /p:DeployOnBuild=True /p:SkipInvalidConfigurations=true /p:WebPublishMethod=Package /p:PackageLocation=$(Build.ArtifactStagingDirectory) /p:PackageAsSingleFile=true to generate a package.
Then in release definition use Deploy: Windows Machine File Copy task - Copy the Web Deploy package to the IIS servers. Finally use Deploy: WinRM - IIS Web App Deployment - Deploy the package. This task running on the Build and Release agent opens a WinRM connection to each IIS server to run Powershell scripts remotely in order to deploy the Web Deploy package.
For more detail/step to step tutorial, you could reference below tutorials, even some are the samples for web app:
End to End Walkthrough: Deploying Web Applications Using Team Build
and Release Management
An ASP.NET MVC Site That’s Easy to Deploy from a TFS Build
Working with Web Deploy and Release Management
Using the IIS WinRM tasks would probably the best and easiest way to do it. You can find some good guidance of how to configure things.
The basics that you need in place are:
Make sure that WinRM is configured on the target server and that your agent can connect to them
Package your web site by adding these msbuild parameters when you compile the project
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=$(Build.ArtifactStagingDirectory)

Deploying ASP.NET Core solution with class library to Azure

I'm working in VS2015 and have a ASP.NET Core solution with two projects - an API Web Project and a Class Library that holds all the data entities, context and Entity Framework migrations. The API project references the class library and all works well on my local machine.
I now want to deploy the solution to Azure and this is where I'm hitting the problem. If I right click on the API project and go through the Azure App Service publish wizard, on the Settings tab I expand Databases and the message is "No databases found for this project" - which I'm guessing is because it can't find a context as it's not in this project.
If I do the same on the CL project though, there is no Azure App Service deployment option, the only option is File System and clearly there's no option to create the database there either.
So, in summary, my question is how I can deploy this type of solution to Azure and have the database created and migrations applied?
I think you need to create the DB first in the azure and then try to publish your application through the wizard. The database is on your local machine and the application will work just fine on your local environment. But on the cloud you have to first create the database on Azure SQL. Then you need to get the SQL connection string from the portal and update your config file accordingly. Once this is done you can then publish your application from Visual Studio. Please note that the wizard will still not show you the databases, but the application, when configured properly will run fine.

Jenkins - MSBuild for ASP.NET CI without local IIS

Background: I am doing a POC for CI using Jenkins and MSBuild. I have installed Jenkins, MSBuild plugin and other required components on my machine and configured as well. But I don't have IIS configured on my development machine.
I want build the ASP.NET website and output the published code in a folder "c:\precompiledweb" using MSBuild script. I have
Can someone help me with MSBUild Script.
Make sure you read the prerequisites for functionality.
https://msdn.microsoft.com/en-us/library/1y1404zt.aspx
Walkthrough: Deploying a Web Site Project by Using the Publish Web Site Tool
Prerequisites
In order to complete this walkthrough, you will need the following:
Visual Studio.
*This walkthrough assumes that you selected the Web Development collection of settings when you started Visual Studio the first time. For more information, see How to: Select Web Development Environment Settings.
Access to Microsoft Internet Information Services (IIS) so that you can test the result of publishing a Web site project. In this walkthrough, it is assumed that you have IIS running on your own computer. Alternatively, you can use any instance of IIS for which you have permission to create a virtual directory.*
You need access to some IIS server.
On the flip side....you need to keep this general rule in mind. Jenkins is simply a fancy wrapper for command line calls.
So test the below (article) on your machine without IIS. If you can get the command line to work (outside of jenkins), most likely you can get it working (inside jenkins)
http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/command-line-deployment
Configure Source Code Management section, i.e. for TFS:
Add build step "Execute Windows batch command"
Insert msbuild invocation to your solution, i.e.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
"%WORKSPACE%\{solution_name}.sln"
You can add some optional parameters.
After build you can add another script invocation (batch, powershell, whatever) for copy project output to specific folder, but I would prefer another way: publish to IIS and run application immediately.
in Visual Studio create publish profile with WebDeploy target (help)
enable Web Deploy in IIS on test machine (help - when componentes are already installed go to "USING THE IIS MANAGER TO CONFIGURE WEB DEPLOY FOR A NON-ADMINISTRATOR" section)
add publish parameters to jenkins job from step 2, i.e.:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
"%WORKSPACE%\ {solution_name}.sln"
/P:DeployOnBuild=true
/p:PublishProfile="{publish_profile_filename}.pubxml"
/p:Configuration=Release
/p:Platform="Any CPU"
/p:Password={Password_for_publish_profile_same_as_used_in_VS}
And now you have jenkins click-once job for build and publish solution to test server. Add Source Code change trigger and you have basic CI.

ASP.NET how to persist user uploaded files across each deploy

I am new to asp.net. I have created an web application and hosted in appharbor.com. I created a folder below the project to store the user uploaded files(\photo\product). However this folder is not persist across each deploy. Is there any common approach to solve this problem? Any guide will be helpful.
I assume you are using WebDeploy to deploy the application to AppHarbor. You can instruct WebDeploy to not delete existing files on the server from MSBuild using the following MSBuild argument:
/p:SkipExtraFilesOnServer=true
OR during the MSDeploy deployment using the following argument:
-enableRule:DoNotDelete

Deploy asp.net web application

I have ASP.NET MVC web application. I need to deploy it which consists of:
1. Changing some of Web.config sections
2. Building under Release configuration
3. Copying to my deployment server (optional)
What are the ways to automate this process?
1. Changing some of Web.config sections
Use the web.config transformation you can implemnt it by modifing the Web.Debug.config and Web.Release.config in your web project
2. Building under Release configuration
3. Copying to my deployment server (optional)
This post should help. Read also this about the publish thing
We use continuous integration via Jenkins/Hudson to build and a task in it to deploy to staging or production that uses msdeploy in a batch script.
For building, our parameters for msbuild for release builds are:
/Target:Clean;Build /Property:Configuration=Release
It does take a while to figure out the msdeploy options but it is worth looking into (it's what Visual Studio is using behind the scenes to do the deploy if you use the GUI-based approach).
In terms of building under release configuration & copying to your deployment server you can use MS-Build alongside a tool like Team City / Team Build to automate the process.
Here is a great post to get yourself up and running: How to use MSBuild to deploy an ASP.NET MVC application

Resources