Programmatically Reloading a C# Project - c#

Is it possible to programmatically reload a C# project? In one of my previous questions I needed to add all the CS files in a specific folder, now while this works I find that I have to reload the project every time to so that it can register the new files were added.
So now I need a way to automatically reload after the project had been generated.

I assume, for the first time when you output all the DAL files, you are also creating a file with extension .csproj listing in it, all the files you just added in the folder.
If my assumption above is right:
When you want to add more files, you can programatically edit the same .csproj file from your c# code. Then, Visual studio will force the project reload saying it has changed outside the environment.
If my assumption above is wrong:
You can create the .csproj file, It should be easy and straight forward.
I am not sure If I got your question right.

Related

Adding new files to the Solution file for asp.net

I have an already existing solution file for my live website. If I add any new files(.aspx page) in my project, I have to explicitly add those new files to the solution by right clicking on the project -> Add -> Existing item -> selecting the files.
Now, after adding the files for the first time, I added few more files later. During that time, I found that the files which I added in my first deployment were missing and I had to add the old files again with the new ones?
Am I doing anything wrong or is that the way it works? Do I need to add all the new files explicitly to the solution every time before publishing to the server?
The issue which I was facing was because my project's ".csproj" file was not getting updated while deploying the project. It is ".csproj" file which keeps track of all the files which have being added newly. Once I updated the particular file in my production environment, I was able to see all my project files and it didn't require manual intervention. Thanks all for your help.

Can I compile a single aspx.cs file into a DLL?

I'm attempting to make a single small update to a website written in C#/ASP.NET.
All I'm trying to do is change the email address a form submits to, which is why I'm not seeking out a proper C#/ASP.NET developer.
I've done a little research, and it seems that the site itself is using dll files in the /bin folder to run the forms and things. The form is contact.aspx.f3293f9sd.dll, so I've edited the corresponding contact.aspx.cs file.
What do I do now?
Can I build this single CS file into a single DLL and upload it? I've scoured the menus and see no such option, and Google results seems to imply that you need to add entire projects and build entire projects at once.
Is that correct? What's the process here?
What you need to do is open the solution file. Solution files are files composed of projects. The contact.aspx.cs file is part of one of those projects. You need to make your change in the file, then recompile your solution. Then you can upload the DLL file it outputs to your production. Make sure you compile in Release mode.

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.

C# can't find properties file, how do I repair this?

I had a Properties file called RecentFileList within my Visual Studio 2012 project and I removed it. I believe it was a .settings file. Now when I run my setup project, it is trying to copy files that it shouldn't care about and it's bombing out as a result. I get 3 errors (-1007 -6271 and -6103), all related to the same missing file.
-6103: Could not find file "C:\Users\Charles\Documents\Visual Studio 2012\Projects\RallyCourses\RallyCourseDesigner\bin\Debug\Properties\RecentFileList.Designer.cs
What file do I need to edit to get rid of the reference to this file? I tried searching for RecentFileList.Designer.cs, but can't find it.
The offending files in my situation were trying to be installed by the installer, but I had removed them from the main project. Within the SetUp project, there is a section Specify Application Data -> Files. I found the files in the Properties section there, removed them, and things are working now...

Where is "Set as Startup" defined and persisted in C# winforms solutions?

I don't see it in the .sln file, which is what I expected.
Which project is the "startup" project only has any relevance for debugging, which means it's user metadata from the point of the solution and the projects. Regardless of which project is the "startup" project, the compiled code is the same.
Because of this, the information is stored as a user setting in the Solution User Options file (solution.suo) which accompanies the Solution file (solution.sln). The .suo file "Records all of the options that you might associate with your solution so that each time you open it, it includes customizations that you have made" according to MSDN.
The .suo file is a binary file. If you want to read or change it programatically, you have to use IVsPersistSolutionOpts.LoadUserOptions from the Microsoft.VisualStudio.Shell.Interop namespace.
It's in the Solutions User Options (.suo) file, which gets created next to the .sln file.
It seems that the first item in the solution's sln file is, by default, the startup project. So, you could manually edit the sln file to make your project the first project in the solution. Then, a user can override that by selecting a different project to be startup.

Categories