ASP.NET Core Deployment Profiles - visual-studio

Having built a Blazor (hosted) application in development environment in blissful ignorance of the challenges of deployment, I now come to my first attempt at deploying.
My intention is to deploy to my local machine on IIS as a 'staging' environment before publishing a 'production' environment to the web.
My first attempt resulted in a snag relating to connection strings, which I believe is because my development settings had used integrated security, but the staged deployment is using IIS Application Pool identity, which does not have the SQL permissions.
Fine. So I think my next step is to create an appropriate appsetting.json file for 'staging'.
What I think I understand:
When 'publishing' the appropriate appsetings.<environment>.json file will be merged with the root appsettings.json file and become the deployed appsettings.json file.
The launchSettings.json file sets the <environment> under one of the 'profiles'.
What I can't get to the bottom of:
How, when I'm publishing from Visual Studio, do I tell it which 'profile' to publish with?
Or have I misunderstood something else?
UPDATE:
I now see that on project properties > Debug tab, I have the opportunity to create an additional "Profile" and set the Environment Variable for ASPNETCORE_ENVIRONMENT to "Staging". From there, I guess I can create an appsettings.staging.json file.
So, I think my question now is:
Do I have to go to the 'Debug' tab and select the profile I want to use BEFORE publish? And then change it back for when I'm doing more work in development?

Related

Why are config transforms not applied when I manually publish a console app as an Azure webjob?

I have a console application that I am deploying to Azure as a Web Job. I do this manually from Visual Studio 2015 by right-clicking the project and choosing "Publish as Azure WebJob".
I am now at a point where I need to deploy this app to several different environments (ex: dev, test, prod etc). In each environment the console app needs to run with different config settings.
To get this done, I've installed Slow Cheetah v2.5.48 and setup multiple config transform files - one for each environment.
I've also created dedicated publish profiles in my project - one for each environment - and I've made sure the profile names match the names of the config transform files.
When I manually publish via the Publish wizard in VS (as described above), I find that the config transforms are not applied. Instead, the "base" .config file are present on the target app service.
Why are the transforms not applied when publishing this way and how can I fix that?
According to your description, I suggest you could firstly check you have already build configuration called "dev" ,” test” like below.
Then I suggest you could check you have a right app config file in your project like below.
At last, you could make sure you have select the right build configuration.
Besides, I suggest you could open your .csproj file and ensure that the App.dev.config tag’s IsTransformFile is true.
<None Include="App.dev.config">
<DependentUpon>App.config</DependentUpon>
<IsTransformFile>True</IsTransformFile>
</None>
I would suggest you try with:
< xdt:Transform="Replace">

How to set default value for <project>.SetParameters.xml for deployment page

During build msbuild creates deployment packages for several my web projects (and wcf services) which I want to run from command line (as last step of automated build process) to deploy to several different servers.
The structure of IIS application folders is the same on each one.
My problem is that I cannot find how to configure (override default value of IIS application). It is in .SetParameters.xml, like:
which is not what I want.
I read that it is possible to create parameters.xml in the project and put there something like:
or some say
I'm trying this but it does not change content of .SetParameters.xml
Can you advice what am I missing, or/and alternative way to do this.
Thanks!
If you want to deploy the web application package manually—either by running the .deploy.cmd file or by running MSDeploy.exe from the command line—there's nothing to stop you manually editing the SetParameters.xml file prior to the deployment. However, if you’re working on an enterprise-scale solution, you may need to deploy a web application package as part of a larger, automated build and deployment process. In this scenario, you need the Microsoft Build Engine (MSBuild) to modify the SetParameters.xml file for you. You can do this by using the MSBuild XmlPoke task.
For more information, please refer to: https://www.asp.net/web-forms/overview/deployment/web-deployment-in-the-enterprise/configuring-parameters-for-web-package-deployment

Copy file during Team City Build

I've got an MVC 5 project stored in Git. I've installed TeamCity 9.1.7 (build 37573) on our build server and I've set it up to successfully perform a build when a developer checks in code to Git. My goal is to deploy the MVC application using MS Web Deploy if the build is successful. I've seen a number of tutorials that suggest using a web deploy package, but these tutorials are six or more years old. Is this still the preferred method for deploying a successful TeamCity build to IIS?
Further, we've added the web.config file to gitignore for a number of reasons. Git houses as Web.config.base that developers will copy to their own web.config file as a starting point. A developer will copy the web.config.base file to web.config when they first pull down the project. I've tried to set up a command line task in TeamCity to xcopy the web.config.base file to web.config
Working Directory: (left blank)
Command: xcopy MyMVCProject\Web.config.base MyMVCProject\Web.config
This build step fails with exit code 4 at all times. I've set the TeamCity build agent service to run as a local administrator. I've tried this as straight command text as above, as a cmd or bat file, and with a variety of different path styles, going so far as to use the TeamCity working directory variable, excluding the MyMVCProject from the path, including the MyMVCSolution in the path, etc. Any ideas as to why the xcopy would fail?
This is the same problem I was facing.
But at last, we put the master web.config file on the server where TeamCity is installed.
Then once the Project gets deployed , I replaced the web.config file with the web.config file which is alreay present on server.
So there will be no conflict in the web.cofig file
You just need to add one more build step after the Web deploy step.
In that you can use Xcopy and you can replaced you web.config file
Hope this will work
WebDeploy is still a great option for deploying ASP.NET web applications. Its even used with the brand new ASP.NET Core framework. We don't use TC but do you WebDeploy/MSDeploy extensively at work to deploy 50+ applications.
Regarding your config setup, I've never seen this approach. We use Parameterization to handle config changes per environment (local dev included). If you're worried about security of the config values, you could secure your SetParameter files which have the sensitive info and include the web.config in source control with default or placeholder values.
http://www.dotnetcatch.com/2014/09/08/parameterizationpreview-visual-studio-extension/

How to add some specific file into the build process?

We are using TFS 2010. In our projects we have multiple configuration files. Each configuration file is needed for a specific build.
Example: Project XYZ includes three configuration files, lets say DEV-CONFING, QA-CONFIG and PROD-CONFIG files.
Now we want to find a way that during the build process, the build process includes the right configuration file and excludes the rest.
Example:
Build for Dev should pickup and copy only the DEV-CONFIG file (and excludes all other configuration files)
Build for QA should pickup and copy only the QA-CONFIG file (and excludes all other configuration files)
Build for production should pickup and copy only the PROD-CONFIG file (and excludes all other configuration files)
Is it possible to change the setting of individual build definition and address this issue?
What is best possible solution for this problem in VS 2010 and TFS 2010?
Please list all required steps and be precise as much as possible because I'm a newbie in TFS 2010 and have not much experience with the whole process.
The "Web Config Transformations in VS2010" addresses the problem of modifying the web.config during compile time. Some people might want the web.config to be modified at deployment time instead of compile time (like me) so that we dont have to recompile the code while moving from one environment to another, in that case you can make use of "Web Deployment Parameters"
You can read more about it at:
http://www.asp.net/mvc/tutorials/deployment/visual-studio-web-deployment/web-config-transformations
web config transformation syntax:
http://msdn.microsoft.com/en-us/library/dd465326.aspx
#user2585405 to your comment above "But all the configurations in my case are for the same mode "Release Mode". The decision should relay on the build definition. So when I use a build definition for DEV, the configuration for DEV should be automatically chosen or for QA build definition, the corresponding QA configuration should be automatically chosen."
Doesnt matter whether currently you have only one configuration. You can add how much ever configurations you want, right click the solution and select the configuration manager. Now add a new configuration say "Dev" (it can be in "Release/Debug" and also select the platform "x86, any cpu etc"). Now add another configuration for QA and PROD. Then come back to your web.config and right click and select "Add web config transformation".
Now you should be able to see the web.Dev.Config, web.QA.config etc. The root web.config will have all the common properties and the DEV/QA/Prod specific config will have only the delta changes (you have to define these entries) which are specific to that configuration (lets say connectionstring). When you compile, within the build definition you can select which configuration you want to compile (Dev, QA, prod) you dont have to keep multiple build defintion. Just one is enough! After the compilation is done, the root web.config will be replaced with the values specific to the configuration for the connectionstring part alone.
Hope this helps!
Yes this possible. You can keep configuration files in different mode for eg:
You can have configuration files in Release mode debug mode, release mode and the common configuration file used by all.
So when you build your solution in Debug mode then the debug mode configuration file will be used and when in release mode then release mode configuration file will be used.
For further clarity take example of web config when you will expand the web config tab you will see the two configuration file in different modes.

Make Debug/Release Build Configuration with 1 Click Publish dependent on the selected Publish Profile

This is almost a duplicate of Link build configuration to a publish profile, but that question was not answered...
I have 2 1 Click Publish configurations for my Web Application:
Test Server
Production Server
If I select Build => Configuration Manager => Release and then click the Publish button my application will be published with a release configuration (and visa versa) - without regard to the current Publish profile selected.
But what I REALLY want is...
To set the appropriate Build Configuration from the 1 Click Publish settings. Test Server should be published with my Debug settings and Production Server should be published with the Release settings.
I shouldn't have to make the change from within the Configuration Manager. But I Do.
So, I have 2 questions:
Am I just doing it wrong? Based on a little note in the Publish Settings stating "Use Build Configuration Manager to change configuration" this seems like this is exactly how it is intended to work.
Is there another way of having 2 publish profiles, one with a Debug config and one with a Release config?
The only thing I'm using the debug/release build configurations for is for my Config Transforms that have different connection strings. So, alternative, but still 1 Click, publishing solutions are acceptable. :-)
It's possible to do another way by having multiple Web Deployment Packages.
Basically create two different projects and each one will compile and set the asp.net build config and output. Then script the deployment as part of it.
Bit hacky (wish the publish profiles could set the build config as you wished).
Other than that I normally do via powershell scripts and kick off from my desktop deploy that does all the appropriate compiling and deployment scenarios.
http://msdn.microsoft.com/en-us/magazine/cc163448.aspx
http://johnnycoder.com/blog/2010/01/07/deploy-aspnet-web-applications-with-web-deployment-projects/
I was able to get this to work by installing the Visual Studio Web Publish Update. This update allows you to tie a build configuration to a specific publish profile.
http://msdn.microsoft.com/en-us/library/jj161045.aspx

Resources