Exporting a Property Sheet in Visual Studio? - visual-studio

Sometimes when working on projects that people have posted online, I have to frantically modify my own property sheets to match theirs in order for my project to work (things like: MTd, linker stuff, Unicode/Multibyte settings).
I was wondering if I could just export a property sheet in Visual Studio for later use instead of creating one from scratch.

Not if you use their project file, its settings are "last" and override anything you'd set in a project property sheet.
Nothing that you couldn't fix with a text editor btw, open the .vcproj or .vcxproj file with, say, Notepad to see how you could delete settings so a property sheet can work. Or copy/paste settings from your own project file.

Related

IDE: Apply property sheet to actual project settings

is anybody aware of a way to apply (as in write or transfer) the settings of a Visual studio property sheet to the actual properties of the project (so they appear explicitly in .vcxproj file)?
I would like to load in a property sheet, transfer the settings to the "real" project's properties (not inherit the settings from the sheet!) so I can remove the property sheet afterward again.
Does the VS IDE allow this?
I am looking for a clickable solution, not a manual transfer.
Thanks in advance
There is no built-in way to do this though you could program an extension or external executable (which is easy to invoke as External Tool in VS) to do this, using e.g the Project class. But it is not that trivial: what do to when conflicting properties are found? Replace them? Combine them? Moreover it sort of defeats the entire purpose of propertysheets which is having a reusable set of options for building.

Visual Studio Project: Properties/Settings.settings Missing

I've checked out a solution from source control and opened it in Visual Studio. My assumption is that this solution compiled at one time (two years ago) and was deployed.
There is a project that contains datasets which I will call the "dataset project". The datasets have connection strings defined in the InitConnection() method in Designer.cs files that are looking for a Properties namespace.
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
private void InitConnection() {
this._connection = new global::System.Data.SqlClient.SqlConnection();
this._connection.ConnectionString = global::<some namespace>.Properties.Settings.Default.<some connectionStringName>;
}
In Solution Explorer, I see a Settings.settings file that appears to be "missing." Indeed, the Properties folder is empty when I check it's contents. The missing settings are compile errors in each dataset.
I've attempted to set the connection strings of the datasets to None, but it tries to save the new value to the .settings file, which fails with a "Warning 22 The custom tool 'SettingsSingleFileGenerator' failed while processing the file 'Properties\Settings.settings'.
" message -- ostensibly because the .settings file is missing.
A little more digging reveals a full compliment of connection strings found in another project which references the dataset project. But the dataset project does not (circularly) reference this other project and would have no way to use its connection strings that I'm aware of.
Can the .settings file be regenerated for the dataset project? Any reason why someone would delete .settings in the first place?
Thanks!
Figured it out.
I used Visual Studio to delete the phantom Settings.settings file under the Properties folder (the "phantom" file icon that the project thinks should be there because it's listed in the .csproj file). Then I opened the project Properties and went to the Settings tab. Visual Studio prompted me to create a new settings file. I happily obliged, and VS automagically imported the settings from app.config.
So it seems there is a way to regenerate the Settings.settings.

Visual Studio: can I copy a project's properties to use in another project?

I've added several directories, libraries such as matlab, opencv, etc to compile my current C file in Visual Studio project.
All my upcoming projects will require the same setup/properties. Do I need to setup my each project's properties individually or I can do something to apply it to all ?
Try using Property Sheets. These can create a single properties file that can be inherited by multiple projects.
Use "View > Other Windows > Property Manager" to bring up the Property Manager. It will show your projects and configurations.
Right click a configuration, and select "Add New Project Property Sheet...". You can name it, and select a location that works for all your projects.
Once created, you can edit its properties just as you would a build configuration.
To use that property sheet as the basis for other projects, just right click the configuration or project, and select "Add Existing Property Sheet...". Browse to where you saved the original sheet, and it will be inherited.
Any changes to the original sheet will be applied to any project that inherits it, unless they are overridden. If you go into properties higher up the chain, properties that override will have bold type for their values. To get them to always use the value in the base sheet, there will be a "inherit from parent or project defaults" option where applicable.
I am using AtmelStudio 6.1, which is built on Visual Studio 2010 (I believe), and yet doesn't have any Property Manager that I can find.
So, the hackish system I use is:
close (or at least unload via the contextual menu) the project whose configuration you want to modify
open its .cproj file (which is XML) in any text editor (VS works nicely),
MAKE A BACKUP COPY OF IT SOMEWHERE ELSE JUST IN CASE,
open the .cproj file of the project whose configuration data you want to copy,
look for the configuration data you want. Configurations are inside of PropertyGroup tags; for example, in my case it looks like
<PropertyGroup Condition=" '$(Configuration)' == 'Preprocess only' ">
for the configuration named "Preprocess only". Copy from the beginning of that tag until the end of the corresponding
</PropertyGroup>
tag.
Paste the block into the destination .cproj, just after other
</PropertyGroup>
tag. Make sure that the name of the configuration is unique in this file. Save.
You're finished. Now open the project normally in VS and you'll be able to select the added configuration.
For Visual Studio 2010+ you can make a Project Template.
If you choose to automatically add the template to Visual Studio in the template creation wizard, when you create/add a new project, the template will appear (after restarting Visual Studio). Projects created with this template will have the same project properties!
To add source code files to the template, the easiest way is to rearrange the source code files in solution-explorer to be in the root (not under any folder). After doing that, THEN generate the template.
Why? Sometimes putting your files under the default Source Code solution-explorer folder (not in file explorer, the .project.filters label) will fail to copy the source file to the template, you'll see "the document cannot be opened. it has been renamed deleted or moved" when you try to use the template and the file you wanted in the template will NOT be in the file explorer.
If you do want solution-explorer folders, you will have to add them manually to the template by unzipping the template folder, making changes, then re-zipping it again.
For example, literally copy and paste the source files you want the template to have in the template folder and edit the .vstemplate file. M$ Doc on template editing.
<TemplateContent>
<!-- put new file references here and/or in your .vcxproj .vcxproj.filters -->
TargetFileName="HelloWorld.cl">HelloWorld.cl</ProjectItem>
<ProjectItem ReplaceParameters="false"
</TemplateContent>
Related questions:
How do I use VS template I created?
How can i load a template I have created in Visual Studio?
How copy visual studio project?
Simply copying and pasting entire projects and solutions is not recommended for complex or shared projects since various GUID s and filenames may overlap - causing bugs.
For MSVS 2017, the process #AaronMK mentioned doesn't work. Instead do the following:
View -> Other Windows -> Property Manager
Add New Property Sheet.
Edit whatever options you want there.
Give it an appropriate name so that you remember it.
Right button on it and hit "Save {myPropertySheet}"
It would be wise to place it alongside the default property sheets and that you can add it whenever you want (by Property Manager -> Add Existing Property Sheet -> Browse to its location). This directory is: C:\Users\{myUsername}\AppData\Local\Microsoft\MSBuild\v4.0
Alternatively you can edit the default property sheets and use these by default. I wouldn't advice it though as they provide a fallback option in case you mess up. So make backups first if editing default files.

How do you remove the bindings from a VS Team project?

How do you remove the bindings from a VS Team project, is it just a matter of deleting ".vspscc" files?
What is the best way to do this, say I have a project on CodePlex and it is time to package it up for release, but by default the bindings come with the source so when others open the solution it interferes with it.
The simple way to unbind from source control:
Open your project
File -> Source Control -> Change Source Control
Select your project(s)
Click "Unbind"
What worked for me (under TFS, not codeplex)
Copy or move the project folder out of your workspace (I put it in c:\temp), and then open it in VS2008.
Visual studio then shows the following prompt:
The solution appears to be under source control, but its binding information cannot be found. Because it is not possible to recover this missing information automatically, the projects whose bindings are missing will be treated as not under source control.
After this, another dialog appears, as follows:
The solution appears to be under source control, but its binding information cannot be found. Because it is not possible to recover this missing information automatically, the projects whose bindings are missing will be treated as not under source control.
And you can chose Temporarily work uncontrolled, or Permanently remove source control association bindings.
Select the latter, do a Save All, and reload the solution. Profit!

How to make the Visual Studio compiler ignore a file?

Is anyone aware of a way to make visual studio completely ignore a file when compiling? I have a C# solution that has a foo.config file that isn't really a standard config file - it's just a text file. During compiling VS grabs a hold of the file and bombs.
I'd like for it to act as though it's just a text file. I do not have the option of changing the name of the file.
EDIT: Please note that BuildAction does not exclude files from the compiler checking them. It simply decides if the file is compiled into the assembly, whether it's content (like a jpg or something), or whether it is a resource file. For more info: see the MSDN page.
EDIT2: Apparently, if you have a text file that is named foo.config and you have it open while building, VS2005 will pop up an error thinking that the file should be xml. However, if you close the file, VS2005 will ignore it.
Solution: Visual Studio validation causes errors if you have a non-compliant file open during build time. For an example of how to turn this off (for HTML), see Scott Guthrie's post. As Allen mentioned, you should also have the Build Action turned to "None". Unfortunately, this will not stop build errors if you have the file open.
right click > properties
Build Action: set to "None"
Edit: If you're talking about app.config, you really cant mess with the format of that, you need to put it in a different .config file.
I just double checked, VS.net doesnt care as long as its not app.config or web.config and the config file build action is set to "None", it will "error" if you have the file open but it will not cause the build to fail or keep it from building the assemblies.
Close the file and the errors will go away, similar to the errors you get about HTML markup. The displaying of these "errors" is probably a configurable setting in vs.net
The action to take depends on the solution and and file type. For instance (in VS2005), in a C++ solution I can right click on the source file name in the solution explorer and view its properties. The first "General" option is "Excluded From Build", which will allow you to exclude the file from the build process without having it excluded from the project altogether.
I pulled up a .config file in a C# solution, and found a "Build Action" option under the Advanced section. That should probably be set to "None".
Just right click on the file and choose "Exclude from project".
If you still want to see it in your project, select the project and click the "Show all files" button at the top of the solution explorer. This will show all the files in the directory tree even if they aren't actually part of the project.
Are you sure that VS compiling .config file???
You should check it's Build Action in file options and may be set it to none.

Resources