create file from solution explorer "missing file" - c#

A small but very annoying issue I have:
In our current working way, all .config files are excluded from source control. Also a .tmpl file with the .config content is included in the source. So when I check out a project from source control I end up with:
[Triangle]Log4Net.config
Log4Net.Config.templ
In my solution explorer. Clicking on the Log4Net.config file (predictably) gives the error, "The item 'Log4Net.config' does not exist in the project directory. It may have been moved, renamed or deleted." Fair enough.
I am looking for a way to "make" that file, like for eg. right click force open, that will open a new empty editor window where I can paste in the content. (I can easily just copy it from the .tmpl file).
Anything like a plugin, or a keyboard shortcut or similar would be what I'm looking for.
Update: To clarify, the .sln/.csproj file(s) are checked in referencing the files. I check this out and open in visual studio. I see the yellow triangle moaning about missing files. Now I need to recreate these files, and I would like to use VS to do so...

Related

Exclude a folder from checkin TFS online

i am using visualstudio.com as TFS online and have created my code repo there.
In my project there is folder that comprises several subfolders and eachsub folder has several images (the total of all images is like 6000).
When i check-in my code I do not want the root folder (i.e. the parent folder of image subfolders) and its content to be checkedin?
I tried online for some answers but cannot find anything accurate.
Thanks in advance for your help.
You can configure which kinds of files are ignored by placing text file called .tfignore in the folder where you want rules to apply. The effects of the .tfignore file are recursive. However, you can create .tfignore files in sub-folders to override the effects of a .tfignore file in a parent folder.
To create the file, the easiest way is using the auto automatically generated .tfignore file, follow below steps:
In the Pending Changes page, in the Excluded Changes section, choose
the Detected changes link.
The Promote Candidate Changes dialog box appears.
Select a file, open its context menu, and choose Ignore this local
item, Ignore by extension, Ignore by file name, or Ignore by folder.
Choose OK or Cancel to close the Promote Candidate Changes dialog
box.
A .tfignore file appears in the Included Changes section of the
Pending Changes page. You can open this file and modify it to meet
your needs.
More info please check the Customize which files are ignored by version control from MSDN Link:Add files to the server
Method 1:
There's an easy way to do it, i.e. via the .tfignore file. Go to the root folder of your and tfs checkin and put following content in the .tfignore file. If the file is not there create it.
.tfignore
<rootfoldername>
Method 2:
To exclude a file from source control
In Visual Studio, open Solution Explorer and select the file to
exclude.
On the File menu, click Source Control, then click Exclude
from Source Control.
When you are ready to place the file under
source control, you can access the File menu and click Source
Control, then uncheck Exclude from Source Control.
Edit:
This question is a possible duplicate of
How to ignore files/directories in TFS for avoiding them to go to central source repository?
Edit:
Changed the file name to .tfignore

Moved Visual Studio Project - Directory Not Found Exception

I have recently copied an entire Visual Studio project (folder containing all files and subfolders) from one machine to another.
I've then opened the project .sln file, and hit debug. The first error that i get it that it can't find Form1 (the very first Windows Form in my project). It gives me the option to select the file manually, but if i navigate to the Form1 file it tells me that the:
Source file is different from when the module was built. Would you like the debugger to use it anyway?
If i do this, the next thing i get is a DirectoryNotFoundException whereby it's looking at this file path:
Could not find a part of the path 'O:\TestDaws\CSDB'.
Now this file path did exist where i was running this program from previously (at work). Now i'm trying to run it from home, it does not. But i cannot find ANYWHERE that refers to the O: drive in my code. Tried searching and it finds nothing.
The only answers i can find seem related to Source Control. And i have no source control. Also seen people recommending deleting the .suo file. I'e tried that and that also has no affect.
The file path it's looking for must be in some meta data or settings file somewhere that Visual Studio creates, and i can't find. Any ideas please?

add pdf file as resource to wpf project and start it from there

I added a pdf file ("myfile.pdf") with "Add Existing Item ..." to my wpf project.
Then I set the properties of it to "Resource" and "Do not Copy" (similar to the properties of other resources that I have, e.g flowdocuments).
Then I tried to execute
System.Diagnostics.Process.Start("myfile.pdf")
and obtained a 'file not found' error.
When I change the file properties to "build: content" and "copy if newer" everything works fine. However, I would prefer not to have this file in my output directory.
I work with VisualStudio Community 2013.
Is it maybe possible that VisualStudio cannot include a pdf file because it cannot compile it?
It's impossible. You can try to write the file from resources to %Temp% and open this File. But you can't control when an external program releases this file and deletes it.

Move VC# Project And Maintain Links

How do you move a Visual Studio C# project and maintain the linked files?
For example;
I have a VC# Project that sits in folder: A/V2013_Project.
This VC# Project links to files A/Image/a.png this is because we have many other projects that use this file also.
I want to move my project to A/Release/V2013_Project. Ie move the project to a sub-folder.
I'm not renaming anything in the new project, not changing anything else except for the location of the project.
When I move the project all my links fail (theres more than 50) and most of my references fail. By fail, I mean they no longer point to the file. Within the newly moved VC# project; when I click on a linked file VC# displays an error:
Cannot find the file A/Image/a.png. It may have been moved or deleted.
But this file was never moved. Its still in exactly the same place.
How can I move a VC# project and maintain the links and references? Are there any 3rd party addons that can do this?
Edit: Using wintermute's advice; the links are indeed relative and not absolute. For example;
<Resource Include="..\..\Resources\Other\Images\TOOLBAR_close.png">
<Link>Resources\Other\Images\TOOLBAR_close.png</Link>
</Resource>
Any ideas how I can make links absolute in VC#?
It depends on how the file is linked. It isn't clear from your question.
Some files are references by the .csproj file. Close Visual Studio down (just to be sure) and open the .csproj file with Notepad or some other text editor. See if the files you're talking about are referenced there. If so, add the text "..\" in front of each file name, indicating they are one directory higher up, relative to the project location.
Some files are referenced in the .resx file(s). In this case Visual Studio should have included the name of the .resx file as part of the error message. This can be fixed using Visual Studio's editor. Double-click on the error message and it should open the .resx file with the file reference that is in error as the selected line. Again, add "..\" in front of the file name.
You say you have 50 references. Hopefully this means you can search-and-replace to add the "..\" text to the relevant file names.
Edit:
You posted an edit to your question, showing this line:
<Resource Include="..\..\Resources\Other\Images\TOOLBAR_close.png">
If you really want to make this absolute, then just do it.
<Resource Include="D:\Merlinia\Trunk-Debug\Add-Ons\Picture Editor\VS2012 projects\PictureEditor\Resources\Other\Images\TOOLBAR_close.png">
But as I mention in a comment on your question, make sure this is the best way to fix the problem.

Windows forms ImageList - Add images with Relative path - No file copy

I'm trying to add images to my tree nodes (ImageList.Add()), but just can't figure out a nice way of doing it.
I've read from MSDN help I should use System.Drawing.Image.FromFile(path). But cannot just get a file somewhere.
I'm building a DLL, and want it to be a single file, no bitmaps being copied together with it.
So I've read I should add Image files to the project and mark them with Build Action as "Resource".
Ok, but where do I get them??? I saw people using it in XAML files, but I don't have that.
Saw people using Resources.SomeName, but can't find those Resources class.
So....How do I do it?? I've got the files marked as resources, just need to add them to the ImageList.
By the way, I'd love to use the path relative to the Code File that is adding the images to the ImageList. But if not possible, just relative to the assembly root.
If you want to use file paths, for items that are in your project, you must set the "Copy to Output Directory" property to "Copy Always" or "Copy if newer", otherwise it won't be in the bin folder, and then you'll be trying to pass a path to a file that doesn't exist. Build action isn't all that important in this scenario.
If you want to use compiled resources, and reference them via the Resources object, see the rest of my answer. I assume you are using Visual Studio, 2005 or later.
To add an image as a compiled resource to a clean Windows Forms project, so that you can access it via Resources.SomeName do the following:
In Solution Explorer, under the windows forms project (mine is called WinFormsApplication1), expand the "Properties" folder. By default this folder should contain: AssemblyInfo.cs, Resources.resx, Settings.settings.
Double-click on the Resources.resx file. This will open an editor for it. You'll probably see a table of strings, with columns "Name", "Value", "Comment".
Click the drop-down arrow on the "Add Resource" button, and select "Existing File", which will allow you to browse to the image you want to add.
You should now see the image appear in a gallery of sorts. Mine has the name TestImage
Now when you edit the code (mine is Fom1.cs), I can access the image as a System.Drawing.Bitmap as Properties.Resources.TestImage.
To my mind, this is the best way to do images that you want compiled into the application. If you want user-added images, you'll need to use OpenFileDialog, or something like that to get your file path. Then the Image.FormFile() will be what you want.

Categories