I am new to SO and also to the C# language. I browsed for a bit and was not able to find anything relating to this subject. I program in other languages, mainly C and C++. When I want to show someone my code I show them the .c or .cpp files and any header files I have created.
However, if I want to show the source code to a program in C# what do I use?
It is especially confusing when I create a new WindowsFormApplicaiton
Technically all you need is the .cs files, but to make it easy on the person receiving this (and assuming you are using Visual Studio) just take the entire Visual Studio project directory (should include a .sln file, one or more .csproj files, all the .cs files, and any other assets) and zip/rar it.
The user on the receiving end can unzip the whole structure and double-click the .sln file, and they will get the same view in Visual Studio that you had.
A little more detail:
Forms are still just c# (.cs text) files.
The .csproj is an XML file that contains pointers to all your .cs files, as well as some project metadata.
The .sln file is an XML file that contains pointers to all your .csproj files, as well as some metadata about source control, project relationships, etc.
When you create a Winforms application, you get two .cs files: Program.cs and Form1.cs. When you are looking at the form, you can right-click on it and choose View Code. This is called a "code behind", and is where the implementation of the form lives.
You can use notepad (open the .cs file) or visual studio. If you don't have a pro copy you can use one of the express editions of visual studio. When in VS you can right click on the form and select View Code. I hope my response is on track with your question!
Related
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.
I have a c# Windows Forms control library, but there is no sln file with it.
I would like to modify this project, so I think I need an sln file to open it and create an other dll.
I tried a solution, but it did not work.
I create a new c# Windows Forms control library, I named it as the original library name.
I renamed the UserControl1.cs as the original mainfile name.
I bult it, it has worked, yet.
After that I copied all of the .cs files from the original library to the new library.
Of course overwrite the new files with the original files.
I tried to build it again, but I got an error message: "dll does not contain any usercontrol types"
The original folder contains a __csproj.user file, but my new project does not contain it.
What did I wrong? How can I modify the original c# Windows Forms control library oe how can I create an sln file for it?
If you don't have .sln file, that's fine visual studio will create it for you when you open a .csproj file and try to save the project.
All you have to do is open the .csproj file in visual studio and save it.
We are moving from SourceSafe to Subversion as our source control provider... All is going well so far except I can figure out how you "share" a file between more than one project. In sourcesafe you made a link to the file and then added it to your project, then source safe knew that the file was really just one file. How do you do the equivalent with Subversion?
You can add a file as a link within Visual Studio directly.
Doing this means you don't have to worry about how your source control will manage things, so long as the referenced file in in source control - the link is managed by VS.
You're looking to share a CS (as in a code file) between 2 projects? From an design aspect, why not extrapolate that file into it's own project and then reference that project from the other projects.
I have a Silverlight 4 app that I'm building with Visual Studio 2010. I'm using Mercurial/TortoiseHG to do version control. Which files do I need to check in? By default, it checks in all sorts of .dlls in /bin/debug and stuff. Do I really need those? Or can I just grab code and content files? Do I need to version something to keep track of project properties and references, or is that contained within the .csproj file itself?
You don't need to include stuff in /bin or /obj. This is true of all VS solutions in source control. These are recreated upon every rebuild. Also, for Silverlight specifically, you don't need to check in the XAP file that is generated in the ClientBin of your web app.
From MSDN (via this social.msdn thread):
You can add the following files to Visual Studio source control:
Solution files (*.sln).
Project files, for example, *.csproj, *.vbproj files.
Application configuration files, based on XML, used to control run-time behavior of a Visual Studio project.
Files that you cannot add to source control include the following:
Solution user option files (*.suo).
Project user option files, for example, *.csproj.user, *.vbproj.user files.
Web information files, for example, *.csproj.webinfo, *.vbproj.webinfo, that control the virtual root location of a Web project.
Build output files, for example, *.dll and *.exe files.
It doesn't say anything specific about Silverlight projects though.
Is Mercurial/TortoiseHG integrated into Visual Studio? i.e. can you check out/submit from within VS?
If so, if you right click on the project name and select "Add Solution to Source Control" it should add those parts of the project that it needs ignoring everything else.
I discovered earlier tonight that files and folders I have removed from my C# projects are apparently still on disk, even though my Visual Studio Mercurial plugin seems to do a good job of deleting them when I delete them in Visual Studio. It must have hickuped when it came to these files.
So I wondered... Does anyone have a script or similar, or know of something, that will look at my .csproj files and report extra files and folders on my disk that isn't part of the project files?
I just want to clean up my repository contents.
Easiest way is to go to the Project menu and choose "Show All Files".
This option is set on a per-project basis.
If you enable the "Show All Files" option in the solution explorer, any files not included in the project file will be shown with white icons.
alt text http://img686.imageshack.us/img686/9986/85818429.png
If you then fully expand the project tree, you should be able to see any file that is not included in the project. Additionally, you will also be able to see any files that are included in the project but are not present on disk (these will have a warning triangle overlaid onto them).
This is a per-project setting, so you will have to do it for each of your projects.