There are multiple alternatives for "release and debug" configuration in visual studio, I would like to know if they serve the same purpose.
1) Option 1: In the Visual Studio toolbar
2) Option 2: In the web.config file
3) Option 3: In the project properties window
4) Option 4: In the publish site configuration window
Is not one of these configuration options enough to deploy an application? Are all of them required? what are the differences?
The first one tells you in which one you are working right now (which configuration will be build if you say build - which one will start if you debug, etc.)
The second one handles what how the server will build your aspx/razor/etc. pages.
The third is there so that you can change the settings of the different configurations in the first place!
The last one tells which configuration you want to deploy - no matter what the current selected configuration (from 1) will show - of course it will depend on the settings in 3 and will most likely deploy the file from 2.
so no - it's not enough to have only one of those
Related
I have a solution that launches multiple projects, and I set the launch profile for both to the console app instead of launching in IIS via the Project Properties page.
When I launched the projects individually they launched successfully in the console windows. But when I set multiple startup projects they went back to launching in IIS.
How can I get multiple projects to launch using the correct debug profile?
To set the default launch profile you can re-arrange the debug profiles listed in Properties > launchSettings.json. The first profile in the list will be the one used when launching multiple projects.
As mentioned in the comment of the other answer, it doesn't seems to be true for VS2022. It does not automatically use the first entry in the launchSettings.json list.
You can change the starting project to a single one and switch the debug profile with the small arrow next to the play button in the toolbar one by one. But if you need to do a mass switch, I suggest doing a "search in all files", it's stored in the .csproj.user files:
<ActiveDebugProfile>Docker</ActiveDebugProfile>
Change them all, then reload your solution.
I have a solution with one project and 3 solution configurations:
Debug
Release
Staging
When I for example choose "Release" in the quick menu toolbar to change the active solution configuration and Hit F5 I expect the solution to be compiled in Release mode, but whoooo it's still debug (Output window). Ok, let's go to the configuration settings and clear it up.
But the IDE will not apply my changes...? What's wrong here?
When I go to solution -> properties -> All Configurations I expected all my configurations to be visible that I have configured. As I have only one project, I expect "Release", "Debug" and "Staging (added by me)" to be present.
But they are all set to debug...
If you open the "Configuration Manager" via the Build entry.
It opens the same "Configuration Manager" when going the route: Right-click Solution --> Properties --> Configuration Manager.
Now you can choose the Active solution configuration for example "Release" and check if the projects configuration is also set to Release, if not change it.
Click Close and rebuild your solution. Now it should build the chosen configuration. You have to repeat these steps for every configuration: Debug|Test|Staging ...etc.
This time it will remember the settings!
When going solution- -> properties it will not, at least in my case.
(1) Make sure your solution file has a configuration set for the release mode you want.
To do this, right-click the solution in Visual Studio and choose Properties. Then use the "Configuration Manager..." button. In the dialog box that appears, for the project you want to add a configuration for, choose the drop down in the Configuration column.
(2) Right-click your project file in Visual Studio and choose Properties. Select the 'Build' tab. Make sure the 'Configuration' drop down menu has the build configuration you want to use and that you have a corresponding 'Conditional compilation symbols:' entry set that matches. See screen shot below.
(3) In your code behind file (.cs for C#). You'll should see the
#if VALIDATION
// Your code when building for VALIDATION
#elif PRODUCTION
// Your code when building for PRODUCTION
#endif
By changing the drop down at the top of the screen, each of the conditions you've coded for should be enabled/disabled (visually by shading of the text) based on the configuration selected.
In Visual Studio, we're using the click-to-publish thingy... is it possible to write a plugin or somehow give a confirmation dialog when you click publish to make sure that's what you want to do? don't want people accidentally overwriting production
I don't know is it possible to turn this on by default, but if not - at first you need to understand how VS does this. Probably this is some msbuild targets file (msbuild task) which has some settings like "Publish = True/False". So what you can do - is to create a new msbuild task which you will invoke before the Publish task (you can try to add this task to your project file). In your task you will check if "Publish = True" - you will show message box "Do you want to publish?" and if somebody will click No, you just need to override "Publish" value in msbuild to False. I think this should work.
I don't know of any plugin which can do this.
One approach to mitigate the risks would be to create multiple configurations combined with multiple publish profiles:
E.g.
configurations: Debug_Development, Release_Development,
Release_Production where, using web.config transforms, set
different settings for connection strings, app settings, etc. (a nice
introduction to web.config transforms, and not only, can be found
here)
publish profiles: debug_development, release_development and release_production, each of them with different ftp settings (if you deploy via ftp) and each of them connected to the corresponding configuration
We're using the Sql Server 2012 SSDT which removed the deploy option in Visual Studio for the database projects (now sql projects). We'd like to automate the Publish step as we had for deploy, but it's not clear how to do this. so thA couple of questions:
I've added the .publish.xml to the project (after the first manual publish, checking add to project). Even after that, and setting it to the default, when I double click it, it builds, but always pops up settings window, where I need to click the "Publish" button to continue. Is there a setting that would skip this prompt and use the current values?
It seems that each publish generates a version of the sql output. How can I suppress this- i.e. overwrite the base file each time?
And lastly, any pointers for updating the build to use the new project type and publish command for the automated builds would be appreciated.
How to restore the Deploy option: (Visual Studio 2010/2012 only -- this is no longer supported in Visual Studio 2013)
The Deploy option is still present but for some reason it's not available in the menus. (Cursed Visual Studio team!) I've worked around this by adding the Deploy option to one of the toolbars as follows:
Click the arrow on the right-hand side of a toolbar.
Click "Add or Remove Buttons", then Customize.
In the Customize dialog click Add Command.
Select the "Build" category, then select the "Deploy Selection" command.
After saving your selection the "Deploy [project name]" option will appear on the toolbar. You'll need to select your project in Solution Explorer for the button to become enabled.
Note that the deployment settings are different than the publish settings. The deployment settings are configured in the project's properties on the Debug tab.
To answer your questions about the Publish option:
1) How to use a specific publish file by default and avoid the annoying prompt
I don't think there's a way around this.
2) How to publish the entire database, not just the changes
Open your .publish.xml file in a text editor and add <AlwaysCreateNewDatabase>true</AlwaysCreateNewDatabase>.
For example:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetDatabaseName>MyDatabase</TargetDatabaseName>
<DeployScriptFileName>MyDatabaseProject.sql</DeployScriptFileName>
<TargetConnectionString>Data Source=localhost\SQL2012;Integrated Security=True;Pooling=False</TargetConnectionString>
<PublishDependentProjects>False</PublishDependentProjects>
<ProfileVersionNumber>1</ProfileVersionNumber>
<AlwaysCreateNewDatabase>true</AlwaysCreateNewDatabase>
</PropertyGroup>
</Project>
3) Command-line syntax for automated builds
First build your project with msbuild as you normally would so that the .dacpac file is created in the bin.
Then use sqlpackage.exe to publish using your .publish.xml file:
C:\Program Files\Microsoft Visual Studio 10.0\Microsoft SQL Server Data Tools\sqlpackage.exe /Action:Publish /SourceFile:C:\[path to my project]\bin\Debug\MyDatabaseProject.dacpac /Profile:C:\[path to my project]\MyDatabaseProject.publish.xml
Note that the path to sqlpackage.exe may be different.
A bit late to the party, I admit, but maybe this will help others who stumble across this discussion. My company is presently moving to VS2012 and we have all three of the same issues as Keith. I have found workarounds for #1 and #2.
For #1, I use AutoHotKey to monitor for the existence of the publish window, and automatically click the "Create Script" button. You could of course have the script automatically click the "Publish" button instead. In this example if the publish profile is not "XYZ" (I always prefer manual intervention for production server deployments) then go ahead and send an Alt+G to generate the script.
#Persistent
SetTimer, ClosePopups, 5000
return
ClosePopups:
if WinExist("Publish Database ")
{
WinActivate, Publish Database
WinGetTitle, TitleText, A
If not TitleText = "Publish Database XYZ.publish.xml" {
Send, !G
}
}
return
For #2, every time we publish it increments the filename with a number suffix and we end up with lots of files in our deployment folder. I just used pre-build events to clear out the .sql and .txt files before the build:
if exist "$(ProjectDir)$(OutputPath)*.publish.sql" del $(ProjectDir)$(OutputPath)*.publish.sql
if exist "$(ProjectDir)$(OutputPath)*.txt" del $(ProjectDir)$(OutputPath)*.txt
The best way I have found to automate the deployment of SSDT database projects is to use msbuild. Originally we were using VSTSDB and used msbuild against the *.dbproj file. As it turned out the arguments for deploying sqlproj files is exactly the same.
Because the old argument list works for us, I didnt swap to using the public.xml file style. There quite a bit of documentation for the vsdbcmd.exe and msbuild against dbproj. I would use that as reference.
Here's argument list, and execution output as we define it for FinalBuilder execution
[ MSBuild Project [ C:\xx\xxx\xx\xx\MyProject.sqlproj ] ]
Configuration : Release
OutDir : C:\Builds\1\xxxxx\builddefname\Binaries\Release\
DeployToDatabase : True
TargetDatabase : ExistingDatabaseName
TargetConnectionString : Data source=.;Integrated Security=SSPI;**
Build started 3/23/2012 2:17:08 PM.
Deployment script generated to:
C:\Builds\1\xxxx\builddefname_FB\Binaries\Release\MyProject.sql
Dropping FK_at_lusys_assetCategory_at_lusys_image...
Creating FK_dcb28374eeabe8e715038984419...
Creating FK_d82897e4acd966d4b136c242cef...
Checking existing data against newly created constraints
Update complete.
Done Building Project "C:\xxx\xxxxxxx\xxxxxxxxx\MyProject.sqlproj" (Deploy target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
and putting together the msbuild command line looks like this:
msbuild XXX.sqlproj /target:Deploy /p:Configuration=xxx;OutDir=xxx;DeployToDatabase=True;TargetDatabase=xxxx;TargetConnectionString="xxxxx";AlwaysCreateNewDatabase=True
I downloaded an ASP.NET open source solution and opened it in Visual Studio 2010. VS is running as admin.
Everytime I switch the solution or a project from Active (Release) to Debug and uncheck 'Optimize code' and save, these changes don't stick. The solution or project reverts back to Active (Release).
Why is this happening?
You also have to change it in Configuration-Manager (see pictures).
I just had this exact issue. The solution ended up being:
Go to Tools ⇒ Options ⇒ Make sure "Show All Settings" in the lower left is checked.
Then, in that same window, go to Projects and Solutions ⇒ General ⇒ check "Show advanced build configurations".
I have no idea why this checkbox was suddenly unchecked for me this morning, but this worked.
This is guessing a little, but anyways:
Most likely, you are using build configurations that don't include your start up project for Debug build.
Look for the 'Manage Build Configurations' (I think, no Windows machine nearby) menu item. It will show you a list of projects with tickboxes on the right to show whether it is to be built in the build configuration.
Switch to 'Debug' in that dialog and make sure your startup project - or the project that your starting the build for - is actually included in the build.
PS It is even entirely possible that the 'misbehaving' project is actually lacking a Debug build (it might have a deviant name, like DebugConsole or something else entirely). In that case, use the Project menu to add a build configuration of the proper name for that single project. Afterwards, check (again) that said build configurations are checked in the 'solution wide' build configuration dialog.
HTH
Changing the properties of a configuration doesn't change the current build configuration. If you open project properties, change from Release to Debug and make some changes, after exiting the dialog, you will build on the same platform as before. To change the platform you're building on, there is a combo-box right above the code - use that. You should have all available configurations in the list. When you open the project preferences dialog, the current configuration will be the default one in the dialog.
I opened the csproj file in a text editor. Noticed there were two PropertyGroup sections which look like duplicates, one was Debug|AnyCPU and the second was Release|AnyCPU. I deleted the second one and the debug one showed up.
Luchian Grigore's answer explains correctly one simple misconception that could lead to this problem and aaaaaaa's answer gives another way of correcting it: there is a dialog that looks like you are selecting the configuration to build but you are actually just selecting the configuration to configure.
However neither of their ways of opening the 'Configuration Manager' actually worked for me -- I had to click on the button configuration manager at the top right of the solution Properties.
(Note that the place where you choose the configuration is called Configuration Manager, whereas the place where you manage the configurations is Properties.)