Set SQLCmd variables based on configuration - visual-studio-2012

I'm trying to set SQLCmd variables based on configuration (Debug / Release, etc) but the Configuration dropdown is greyed out (see image below). For Dev environment, I want the SQLCmd variable to be Stage, for the Release environment, Prod.
I can't figure out an easy way to do this without going into the properties. We have 9 projects and about 6 variables each. Each time we do a schema comparison we have to manually change the variables and it's very tedious.
Our publish scripts are fine for the different environments, it's just setting up for schema compare that makes it time-consuming.

Related

Azure Devops Powershell task: Programmatic Access of Build Variables

Hi I want to know if I can programatically access my release variables in the powershell release task. My use case is this: I want to create a generic powershell script that can be used to deploy to multiple environments. I want to set an environment variable on the powershell task that will specify env=dev or test or prod, etc. So I want the powershell script to dynamically access the appropriate build variables (without creating a massive switch statement) based on the environment variable. I'm able to access the environment variable just fine.
So I have this:
$deployenv = "${Env:kudu.env}" #(this works just fine)
$apiUrl = '$(dev.kudu.url)' #(when hard coded like this it works fine)
Currently $apiUrl is able to retrieve the release variable just fine but I don't want to hard code "dev" in the param name.
I've tried a bunch of things like
$apiUrl = variables["$deployenv.kudu.url"]
So I'm wondering is that a way to programatically access these release variables from my powershell task?
You're trying to implement a solution to the wrong problem. The actual problem is that you're not using variable scopes properly.
Use the same variable names across your environments and define different values at different scopes. i.e. the DEV environment has a Kudu.Url variable set to the value for the dev environment. The QA environment has a Kudu.Url set to the value for the QA environment. And so on.

Sharing / transforming appsettings across projects and environments

I got a Visual Studio solutions with multiple projects (function apps and a web API) and a datalayer that is shared between all the projects. I've set up the solution so all projects share the same config (appsettings.json) based on this article: https://andrewlock.net/sharing-appsettings-json-configuration-files-between-projects-in-asp-net-core/
All projects are based on .net core.
I've set up a build and a release pipeline for the dev environment. But I need a Test and production environment. How do I transform the shared config before releasing it to the test and production environment?
You don't. That's not how configuration works in ASP.NET Core. Configuration is overridden, not transformed. There's an order of ops to how the different configuration sources are applied, which is basically the order in which they're registered. The default is JSON < Environment-specific JSON < User Secrets < Environment Variables < Command-line Arguments.
If you need configuration to vary by environment, you're going to rely on the environment-specific JSON files (for general config) or environment variables and/or something like Azure Key Vault (for secrets). Since all of these come later in the configuration registration, any value you set there will override the values in your appsettings.json.
For things like environment-specific JSON, which is loaded is dependent on the value of ASPNETCORE_ENVIRONMENT, which can be set as an environment variable or passed as a command-line argument --environment. In either case, the value set corresponds to the {environment} portion of appsettings.{environment}.json. In other words, if you set the environment as Production, then appsettings.Production.json will be loaded into the config, if it is present. Environment variables are tied to the environment itself so are not dependent on any particular environment value.

Set Config property based on deployment platform (dev, staging, qa, production) in Node.js

In Node.js, I want to set config property value based on platform (dev, staging, qa, production) it will get deployed.
So for example for dev and staging environment, I want to set value '234'
And for prod, i want to set value '456'.
for deployment, i am using VSTS.
Shall I make the use of deployment variables?
For setting config property based, please take a look at this question: Node.js setting up environment specific configs to be used with everyauth
In VSTS Release, you could use environment scoped value per environment.
Share values across all of the tasks within one specific environment
by using environment variables. Use an environment-level variable for
values that vary from environment to environment (and are the same for
all the tasks in an environment). You define and manage these
variables in the Variables tab of an environment in a release
pipeline.
Source Link: Custom variables
If you want to change values, suggest you to use Replace Tokens task Visual Studio Team Services Build and Release extension that replace tokens in files with variable values.

Visual Studio Team Services Web.Config substitute variables

Before I was shown Octopus Deploy I thought that environment dependent appSettings should be a part of Build Configuration in project properties.
Now in times of software as a service it is a deployment process that buckles everything up.
I want my environment configuration in release process to just open web.config and substitute appsettings and connection strings based on variable names i defined for the release definition.
How can I do it? The closest I could get was Magic chunks. The problem with it is that I have to give it a json with the mapping and I have to define it for each environment separately, so it makes no use of environment variables, really, or at least you have to define it in "enviroment variables" section and then, again, in each process of environment.
You can use the "Tokenizer" task in "Release Management Utility tasks" extension or "Replace Tokens" task.
These tasks can replace the strings in a file with the custom variables in definition.

MsBuild build bits but deliver web.config per environment

Is it possible to create a build with VS2012 (and TFS2012), based on a changetset id, that delivers a set of binaries (web) and a set of web.configs per enviroment ?
Is it possible to create a build with VS2012 (and TFS2012), based on a
changetset id
Yes queue a new build, when the confirmation window appears, goto the parameters tab and under GetVersion enetr the changeset you want to build for, you may have to enter a C or a CS infornt, i.e. for changeset 999 c999 or cs999.
that delivers a set of binaries (web) and a set of web.configs per
enviroment ?
Your binaries 'should' be target environment agnostic so you should be able to build once, deploy many times. your config files will depend on how you set them up, if you use the transform mechanism your configs will be created based on your Build configration. if you do your transforms a different way, you could add a post build task to copy the configs 'n' amount of times and then do a find replace type action to enter your environment specific config into each file

Resources