You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ide/managing-application-settings-dotnet.md
+21-13Lines changed: 21 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Manage application settings (.NET)
3
-
description: Manage application settings that aren't included in the application code but are needed at runtime with the Visual Studio integrated development environment (IDE).
4
-
ms.date: 03/16/2023
3
+
description: Manage application settings that aren't included in the application code but are needed at runtime with the Visual Studio IDE.
4
+
ms.date: 05/31/2024
5
5
ms.topic: conceptual
6
6
f1_keywords:
7
7
- msvse_settingsdesigner.err.nameblank
@@ -11,6 +11,7 @@ author: anandmeg
11
11
ms.author: meghaanand
12
12
manager: mijacobs
13
13
ms.subservice: general-ide
14
+
#customer intent: As a developer, I want to use application settings to store information that isn't included in the application code at runtime.
14
15
---
15
16
# Manage application settings (.NET)
16
17
@@ -19,7 +20,7 @@ Application settings enable you to store application information dynamically. Wi
19
20
> [!NOTE]
20
21
> Application settings replace the dynamic properties used in earlier versions of Visual Studio.
21
22
22
-
Each application setting must have a unique name. The name can be any combination of letters, numbers, or an underscore. However, the name can't start with a number, and it can't have spaces. The name is changed through the `Name` property.
23
+
Each application setting must have a unique name. The name can be any combination of letters, numbers, or an underscore. The name can't start with a number, and it can't have spaces. The name is changed through the `Name` property.
23
24
24
25
Application settings can be stored as any data type that is serialized to XML or has a `TypeConverter` that implements `ToString`/`FromString`. The most common types are `String`, `Integer`, and `Boolean`. You can also store values as <xref:System.Drawing.Color>, <xref:System.Object>, or as a connection string.
25
26
@@ -39,9 +40,9 @@ The project system stores application settings in two XML files:
39
40
40
41
- An *app.config* file, which is created at design time when you create the first application setting
41
42
42
-
- A *user.config* file, which is created at runtime when the user who runs the application changes the value of any user setting.
43
+
- A *user.config* file, which is created at runtime when the user who runs the application changes the value of any user setting
43
44
44
-
Notice that changes in user settings aren't written to disk unless the application specifically calls a method to do so.
45
+
Changes in user settings aren't written to disk unless the application specifically calls a method to do so.
45
46
46
47
## Create application settings at design time
47
48
@@ -51,14 +52,14 @@ At design time, you can create application settings in two ways:
51
52
52
53
- Use the **Properties** window for a form or control, which allows you to bind a setting to a property.
53
54
54
-
When you create an application-scoped setting (for example, a database connection string, or a reference to server resources), Visual Studio saves it in *app.config* file with the `<applicationSettings>` tag. (Connection strings are saved under the `<connectionStrings>` tag.)
55
+
When you create an application-scoped setting (for example, a database connection string, or a reference to server resources), Visual Studio saves it in the *app.config* file with the `<applicationSettings>` tag. Connection strings are saved under the `<connectionStrings>` tag.
55
56
56
57
When you create a user-scoped setting (for example, default font, home page, or window size), Visual Studio saves it in *app.config* file with the `<userSettings>` tag.
57
58
58
59
> [!IMPORTANT]
59
60
> When you store connection strings in *app.config*, you should take precautions to avoid revealing sensitive information, such as passwords or server paths, in the connection string.
60
61
>
61
-
> If you take connection string information from an external source, such as a user who supplies their user ID and password, you must be careful to ensure that the values you use to construct your connection string don't contain additional connection string parameters that change the behavior of your connection.
62
+
> If you take connection string information from an external source, such as a user who supplies their user ID and password, ensure that the values you use to construct your connection string don't contain additional connection string parameters that change the behavior of your connection.
62
63
>
63
64
> Consider using the Protected Configuration feature to encrypt sensitive information in the configuration file. For more information, see [Protect connection information](/dotnet/framework/data/adonet/protecting-connection-information).
64
65
@@ -71,17 +72,24 @@ You can add customized settings files to your project for convenient management
71
72
72
73
For example, you can add a *SpecialSettings.settings* file to your project. While your `SpecialSettings` class isn't exposed in the `My` namespace, **View Code** can read the custom settings file that contains `Partial Class SpecialSettings`.
73
74
74
-
The **Settings Designer** first searches for the *Settings.settings* file that the project system creates. This *Settings.settings* file is the default file that the [**Project Designer**](reference/project-properties-reference.md) displays in the **Settings** tab. The *Settings.settings* file is located in the *My Project* folder for Visual Basic projects and in the *Properties* folder for Visual C# projects. The **Project Designer** then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there. If you add a *.settings* file elsewhere in your project, the **Project Designer**won't be able to locate it.
75
+
The **Settings Designer** first searches for the *Settings.settings* file that the project system creates. This *Settings.settings* file is the default file that the [Project Designer](reference/project-properties-reference.md) displays in the **Settings** tab. The *Settings.settings* file is located in the *My Project* folder for Visual Basic projects and in the *Properties* folder for Visual C# projects. The **Project Designer** then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there. If you add a *.settings* file elsewhere in your project, the **Project Designer**can't locate it.
75
76
76
77
## Access or change application settings at runtime in Visual Basic
77
78
78
-
In Visual Basic projects, you can access application settings at runtime by using the `My.Settings` object. On the **Settings** page, select the **View code** button to view the *Settings.vb* file. *Settings.vb* defines the `Settings` class, which enables you to handle these events on the settings class:<xref:System.Configuration.ApplicationSettingsBase.SettingChanging>, <xref:System.Configuration.ApplicationSettingsBase.PropertyChanged>, <xref:System.Configuration.ApplicationSettingsBase.SettingsLoaded>, and <xref:System.Configuration.ApplicationSettingsBase.SettingsSaving>. Notice that the `Settings` class in *Settings.vb* is a partial class that displays only the user-owned code, not the whole generated class. For more information about accessing application settings by using the `My.Settings` object, see [Access application settings (.NET Framework)](/dotnet/visual-basic/developing-apps/programming/app-settings/accessing-application-settings).
79
+
In Visual Basic projects, you can access application settings at runtime by using the `My.Settings` object. On the **Settings** page, select the **View code** button to view the *Settings.vb* file. *Settings.vb* defines the `Settings` class, which enables you to handle these events on the settings class:
79
80
80
-
The values of any user-scoped settings that the user changes at runtime (for example, the position of a form) are stored in a *user.config* file. Notice that the default values are still saved in *app.config*.
If any user-scoped settings are changed during runtime, for example in testing the application, and want to reset these settings to their default values, select the **Synchronize** button.
86
+
The `Settings` class in *Settings.vb* is a partial class that displays only the user-owned code, not the whole generated class. For more information about accessing application settings by using the `My.Settings` object, see [Access application settings (.NET Framework)](/dotnet/visual-basic/developing-apps/programming/app-settings/accessing-application-settings).
83
87
84
-
It's a recommended best practice to use the `My.Settings` object and the default *.settings* file to access settings. It's recommended because you can use the **Settings Designer** to assign properties to settings, and, additionally, user settings are automatically saved before application shutdown. However, your Visual Basic application can access settings directly. In that case you have to access the `MySettings` class and use a custom *.settings* file in the root of the project. You must save the user settings before ending the application, as you would do for a C# application (as described in the following section).
88
+
The values of any user-scoped settings that the user changes at runtime, for example, the position of a form, are stored in a *user.config* file. The default values are still saved in *app.config*.
89
+
90
+
If any user-scoped settings are changed during runtime, for example in testing the application, and you want to reset these settings to their default values, select the **Synchronize** button.
91
+
92
+
We recommend that you use the `My.Settings` object and the default *.settings* file to access settings. You can use the **Settings Designer** to assign properties to settings, and, also, user settings are automatically saved before application shutdown. However, your Visual Basic application can access settings directly. In that case you have to access the `MySettings` class and use a custom *.settings* file in the root of the project. You must save the user settings before ending the application, as you would do for a C# application, as described in the following section.
85
93
86
94
<!-- markdownlint-disable MD003 MD020 -->
87
95
## Access or change application settings at runtime in C#
@@ -99,7 +107,7 @@ You must explicitly call the `Save` method of this wrapper class in order to per
99
107
Properties.Settings.Default.Save();
100
108
```
101
109
102
-
For general information about accessing application settings through the `Settings` class, see [Application settings overview (.NET Framework)](/dotnet/framework/winforms/advanced/application-settings-overview). For information about iterating through the settings, see this [forum post](https://social.msdn.microsoft.com/Forums/vstudio/40fbb470-f1e8-4a02-a4a0-9f62b54d0fc4/is-this-possible-propertiessettingsdefault?forum=csharpgeneral).
110
+
For general information about accessing application settings through the `Settings` class, see [Application settings overview (.NET Framework)](/dotnet/framework/winforms/advanced/application-settings-overview).
Copy file name to clipboardExpand all lines: docs/ide/managing-project-and-solution-properties.md
+21-9Lines changed: 21 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,30 @@
1
1
---
2
2
title: Manage project and solution properties
3
3
description: Manage both the project properties and the solution properties in Visual Studio for C#, Visual Basic, F#, C++, and JavaScript projects.
4
-
ms.date: 05/26/2023
4
+
ms.date: 05/31/2024
5
5
ms.topic: conceptual
6
6
author: anandmeg
7
7
ms.author: meghaanand
8
8
manager: mijacobs
9
9
ms.subservice: general-ide
10
+
#customer intent: As a developer, I want to understand product and solution properties in Visual Studio to manage different kinds of projects.
10
11
---
11
12
# Manage project and solution properties
12
13
13
-
Projects have properties that govern many aspects of compilation, debugging, testing and deploying. Some properties are common among all project types, and some are unique to specific languages or platforms.
14
+
Projects have properties that govern many aspects of compilation, debugging, testing, and deploying. Some properties are common among all project types, and some are unique to specific languages or platforms.
14
15
15
16
You access project properties by right-clicking the [project node](use-solution-explorer.md#solution-explorer-ui) in **Solution Explorer** and selecting **Properties**, or by typing **properties** into the search box on the menu bar and selecting **Properties Window** from the results.
16
17
17
18
::: moniker range="vs-2022"
19
+
18
20
:::image type="content" source="media/vs-2022/properties-from-solution-explorer-context-menu.png" alt-text="Screenshot of the Solution Explorer context menu with the Properties option highlighted.":::
21
+
19
22
::: moniker-end
20
23
21
24
::: moniker range="vs-2019"
25
+
22
26
:::image type="content" source="media/vs-2019/properties-from-solution-explorer-context-menu.png" alt-text="Screenshot of the Solution Explorer context menu with the Properties option highlighted.":::
27
+
23
28
::: moniker-end
24
29
25
30
.NET projects might also have a properties node in the project tree itself.
@@ -35,26 +40,34 @@ Project properties are organized into groups, and each group has its own propert
35
40
36
41
### C#, Visual Basic, and F# projects
37
42
38
-
In C#, Visual Basic, and F# projects, properties are exposed in the [.NET **Project Designer**](reference/project-properties-reference.md).
43
+
In C#, Visual Basic, and F# projects, properties are exposed in the [.NET Project Designer](reference/project-properties-reference.md).
39
44
40
-
The following screenshot shows the **Build** property page in the .NET Project Designer for a console project in C#:
45
+
The following screenshot shows the **Build** property page in the .NET **Project Designer** for a console project in C#:
41
46
42
47
::: moniker range="vs-2022"
48
+
43
49
:::image type="content" source="reference/media/vs-2022/project-properties-designer-build-csharp.png" alt-text="Screenshot of the Project Designer, with the Build tab selected.":::
50
+
44
51
::: moniker-end
45
52
46
53
::: moniker range="vs-2019"
54
+
47
55
:::image type="content" source="reference/media/vs-2019/project-properties-designer-build-csharp.png" alt-text="Screenshot of the Project Designer, with the Build tab selected.":::
56
+
48
57
::: moniker-end
49
58
50
-
The following screenshot shows the **Compile** property page in the .NET Project Designer for a console project in Visual Basic:
59
+
The following screenshot shows the **Compile** property page in the .NET **Project Designer** for a console project in Visual Basic:
51
60
52
61
::: moniker range="vs-2022"
62
+
53
63
:::image type="content" source="reference/media/vs-2022/project-properties-designer-compile-visual-basic.png" alt-text="Screenshot of the Project Designer, with the Compile tab selected.":::
64
+
54
65
::: moniker-end
55
66
56
67
::: moniker range="vs-2019"
68
+
57
69
:::image type="content" source="reference/media/vs-2019/project-properties-designer-compile-visual-basic.png" alt-text="Screenshot of the Project Designer, with the Compile tab selected.":::
70
+
58
71
::: moniker-end
59
72
60
73
For more information about each of the **Project Designer** properties, see [What is the .NET Project Designer](reference/project-properties-reference.md).
@@ -64,19 +77,18 @@ For more information about each of the **Project Designer** properties, see [Wha
64
77
65
78
### C++ and JavaScript projects
66
79
67
-
C++ and JavaScript projects have a different user interface for managing project properties. The following screenshot shows a C++ project property page (JavaScript pages are similar):
80
+
C++ and JavaScript projects have a different user interface for managing project properties. The following screenshot shows a C++ project property page. JavaScript pages are similar.
68
81
69
82
:::image type="content" source="media/vs-2022/properties-page-cpp-console.png" alt-text="Screenshot of the C++ project properties page.":::
70
83
71
84
For information about C++ project properties, see [Work with project properties (C++)](/cpp/build/working-with-project-properties). For more information about JavaScript properties, see [Property pages, JavaScript](../ide/reference/property-pages-javascript.md).
72
85
73
86
## Solution properties
74
87
75
-
To access properties on the solution, right-click the [solution node](use-solution-explorer.md#solution-explorer-ui) in **Solution Explorer** and select **Properties**. In the dialog, you can set project configurations for **Debug** or **Release** builds, choose which projects should be the startup project when **F5** is pressed, and set code analysis options.
88
+
To access properties on the solution, right-click the [solution node](use-solution-explorer.md#solution-explorer-ui) in **Solution Explorer** and select **Properties**. In the dialog box, you can set project configurations for **Debug** or **Release** builds, choose which projects should be the startup project when you select **F5**, and set code analysis options.
76
89
77
-
Solution properties are stored in a Solution User Options (.suo) file. For more information about this file type, see the "[**Solution file**](solutions-and-projects-in-visual-studio.md#solution-file)" section of the [Solutions and projects in Visual Studio](solutions-and-projects-in-visual-studio.md) page.
90
+
Solution properties are stored in a Solution User Options (*.suo*) file. For more information about this file type, see [Solution file](solutions-and-projects-in-visual-studio.md#solution-file).
78
91
79
92
## Related content
80
93
81
94
-[What are solutions and projects in Visual Studio?](../ide/solutions-and-projects-in-visual-studio.md)
82
-
-[Managing solution and project properties (Visual Studio for Mac)](/visualstudio/mac/managing-solutions-and-project-properties)
0 commit comments