Why cannot add resources to the folder in VS 2010 Express? - visual-studio-2010

Hi
In order to be able to work with e.g. picture, I need to click on Resources.resx and Add Existing Item.
Then it will appear under Resources folder. However I could use Context menu on that Resource folder and add existing item as well but then I cannot work with it and it is not displayed when I use the Resources.resx file.
So I always need to click on Resources.rext when I want to add anything? Also in this "view" I cannot use folders so its pretty messy.
Also what is New Folder in Resources dir good for - when I drag files there, there are not accessible anymore..

Correct; to add something to a ResX file, you need to add it to the ResX file.
Instead of folders, you can use multiple ResX files.
You can also embed images in your assembly (set Build Action to Embedded Resource) instead of using ResX files; you can then create arbitrary directory trees.
To read embedded resources, call typeof(MyType).Assembly.GetManifestResourceStream(name) and remember to close the stream in a using statement.

Related

Creating shortcuts to source code files with VS

I know about bookmarks, but what I am really after is the ability to have bookmarks to source files within or outside the project, is there such a thing as bookmarks folder in VS.
PS : This is for reference purpose only and not to include a file in the project as a linked file.
You can use my Favorite Documents extension to create menu links to files within or outside the project.

Copying assets into UWP application package

I have a large folder structure with a ton of subfolders that I am using for application data in my UWP app. When testing, I can just have it sitting on disk and it's fine, but when I make a store package, I need to be able to copy that data in. The only way I've found to include assets is to manually add individual files into Visual Studio and set them to be "Content". Is there a way to copy in an entire folder as "Content" and preserve its folder structure?
You don't have to manually add all the files. Add the entire folder inside the UWP app folder. Once you do that you should be able to use the Show All Files option in the solution explorer and add the entire folder. If the property of the added files is not already set to "Content", multi select the files and set the Build Action property in the Properties window to Content
[]
[]

Change default Add File path in Visual C++ 2010

When adding a new item in a Visual C++ project, the default path for the new file is the project path. Are there any per-project or per-solution settings that allow this default path to be modified?
For example, to add new files by default to a subdirectory of the project folder, or even to somewhere outside the project folder?
I understand that filters can be used to automatically organize files visually within the Solution Explorer based on file extension, but I would like to actually place the physical file in another location without the need to browse to it.
I'm using a Visual C++ project as a container to to manage and organize (filter) editing of runtime-compiled files, and don't want developers to accidentally place new files outside of the intended folder, nor do I want the project file to exist in this code folder.
I did discover that if you create a new file in a sub directory of the project, that the Add Item dialog will default to that path when you add another file during that session, but it does not persist the default to the project or solution for future sessions.
I don't believe there's anything built-in. Some commercial add ins make the behavior better. For example, Whole Tomato's Visual Assist X package always uses the same directory as the currently open file, IIRC.
There are a couple of open source add ins that let you modify the behavior. For example, this one.

How can I include .pdf files when I publish but not in a search and replace in visual studio?

More specifically my problem is if I include a pdf in my project and set its build action to content so it gets copied to the server when I publish, is there a way to exclude it from visual studios search and replace feature. Would a post build action be a solution to this? I just don't want anybody to do a global search and replace in my project and mess up the pdfs...
I know I just said a mouth full so let me know if you need clarification. Thanks!!!
If you look in the section headed "Find options" in the find dialog, there is an option titled "Look at these file types". If you qualify the type as *.cs, it will only look in files with that extension. You can also enter multiple file extensions. As long as you don't include pdf files in that filter, it will not apply to them. An alternative is to define a folder set to search in by clicking the ... next to the folder combo. Put your PDF files into a sub-directory of your project and exclude that folder from the folder set.
Additionally, as you have said, not including them in the project and using a post-build event to copy them to the output would also work.
I would qualify though that you are trying to solve a problem that shouldn't really be a problem. The onus is on the developer doing a find and replace to take care in doing so, and to not replace the contents of files they don't intend to change in the first place. Find an replace can be a dangerous tool.

How is "Add Existing Item..." in Visual Studio meant to work?

I never use "Add existing item..." feature in Visual Studio's Solution Explorer because it is confusing:
it seems to me the way it should work is that if you have a Customer.cs file in Models directory, that you could choose "Add existing item", it would then show you which items exist in that directory an allow you to choose one. Instead, it opens a file dialogue to some seemingly random directory on your hard drive, and I'm not sure if it is going to make a copy of that file, or use it outside the solution, etc.
instead, if I want to "add an existimg item", I go into windows explorer, click file, CTRL-C, click folder in solution explorer, ctrl-v, and it is clear
Do others do it differently? Am I missing something about how "add existing item" in solution explorer is supposed to work?
The folder opens where-ever you last left it...
As for using this feature; by default (Add) it does IMO the least useful thing; copy the file. But if you notice, the add button is actually a drop-down; hit the down arrow and you can add a link to the file - i.e. leave it where it is and reference it by location (Add As Link).
The quick and easy way to do what you are trying to do (add an existing file that already exists within the folder in your project) is:
At the top of the Solution Explorer window is an icon/button for "Show All Files", enable it (if it is already enabled and the file you are looking for is not shown, click "Refresh"). Note that this setting is enabled on a per project basis.
Right click on the file that you want to include and select "Include in Project".
Add Existing file adds the file to the project. Keeping it in the project directory is something different and making it a part of the project is something different. By making it a part of the project, its entry is made in .csproj/.vcproj/etc and then further properties can be set of this file such as specifying a custom build step etc.
And No, it doesn't create a copy of the file in your current project's directory in case of a Visual C++ project. In case of a CSharp Project, it does create a copy.
e.g., I use this when I need to add a bitmap/png file in my project which I have gotten from an external source. I just copy the file to my project directory and then use Add Existing File to add this to the project.
I'm using it. I even didn't know it's possible to ctrl+c ctrl+v in solution explorer.
It's particulary handy, if you want to add something 'as link'.
I do use it but often I just add file as a link. That make it easier to maintain some common classes if you do not want to make full assembly out of them.
As far as my experience goes using this function, it does the same copy and paste that you are describing.

Resources