Remove non referenced files from project - visual-studio

Is there any way in Visual Studio 2013 that i can remove non references files from my solution? I have had some issues with a backup script which has caused all deleted or moved files to be replaced with older versions from the old path. My project is healthy and working but i have lots of old files lurking in the project directories. I could do them manually but it would be very time consuming as the project is large and the problem has been going on for a long time without me knowing...

If the files are referenced you can then either remove them with Visual Studio (Remove from Project), or you can edit the visual studio project (csproj/vsproj/...) and remove them there.
If the files are not referenced by the Visual Studio project, then you have no other option than to remove them manually. The only alternative would be to create a piece of script that will open the Visual Studio project to get the referenced files, and then it will traverse your dictionaries to remove the code files not referenced by the Visual Studio project file - this is doable.

Related

Copying projects/solutions from VS2015 to VS2017

I have a number of projects and solutions developed under Visual Studio 2015 and sitting underneath my Documents\Visual Studio 2015\Projects folder.
I want to copy the projects over to my VS2017 instance for transition testing, so that they sit under Documents\Visual Studio 2017\Projects.
I have a vague recollection that this hasn't worked out so well before due to paths being stored in the various Visual Studio files. In addition, when doing a demo run with a scratch project, the time stamp of the project file in VS2015 was updated, even though it appears no files within there were changed.
Is it safe just to copy over the directories and open the solution files with the newer Visual Studio.
Note that I don't want to affect the original files in any way, they need to stay in VS2015 land.
After testing, it appears this is safe.
Tests involved copying the directories as they were over to the VS2017 area, then renaming the top level of the VS2015 area so that any references, should they exist, would more than likely show up as an error.
With the old area renamed, the copied solutions could be opened in VS2017 without issue, and upgraded to that toolset.
The updating of the directory timestamp was almost certainly a different issue, probably because I had opened one of the files in that directory with vim, which created and deleted a temporary file.

Move actual file instead of a link to other project in Visual Studio

I've been a working with java and Eclipse up until now and moving files between directories was quite easy, just drag & drop and you're done.
Now I moved to Visual Studio 2015 due to C++. So I accidentally created a file in the wrong project and wanted to move it to the right one. However, VS just creates a link to the real file which is still in the other project instead of actually moving the file. To solve this, I used my system explorer but is there a way to do this in Visual Studio directly?
This is extremely annoying. 2 files were missing after I exported my project a few days ago.

Excluding files in Visual Studio project

I've search everywhere for this, but have yet to find the answer.
I have a VS2012 project with thousands of files and folders I wish to exclude from the project as I don't need them to build any longer. Clicking on the folder and choosing Exclude From Project works, but takes literally forever - at times it appears Visual Studio has stopped running and I have to kill the process.
Question: What is Visual Studio actually doing to exclude a file from a project? Is there a way to simply go into the project file and exclude the files by folder? My project file does not appear to store this information. Where are excluded files defined for the project?
You can open the project file (in s text editor, i.e. Notepad) and remove the lines with the files that you want to exclude.
You can also do that in visual studio but you first need to unload the project (right-click on the project, unload)
Delete the folder in VS which has project to unload then restore it from recycle bin.
It works for me.

Editing "testproject.zip" to stop "UnitTest1.cs" being created

I've been modifying the VS2010 item and project templates so each time we do a "new project" or "new item" we get it created in a format that works for us. This is all working fine; if we create a new class library we get it with the references we've set up and it doesn't create the "class1.cs" file - that all works. We've made a similar change to the TestProject.zip file that lives in:
C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\ProjectTemplates\CSharp\Test\1033
Gone through the same process of zipping it back up, copying it over top of the original and refreshing the cache. However for the test project we can't stop it creating the default "unittest1.cs" file. All of our other changes to the test project are working fine but we just can't stop it creating the "unittest1.cs" file. It was never in the template or csproj file originally so I'm not sure what is creating it.
Can anyone help? What creates the default test file for the test project - I'm wondering if it's a reference to the wizard that is in the template file but have no idea what changes would be needed.
Close Visual Studio
Extract BasicUnitTest.zip from:
C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\ItemTemplates\CSharp\1033
Open BasicUnitTest.vstemplate
Remove <ProjectItem ReplaceParameters="true">UnitTest.cs</ProjectItem>
Zip BasicUnitTest.vstemplate into BasicUnitTest.zip (excluding UnitTest.cs)
Go to:
C:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\ItemTemplatesCache\CSharp\1033
Delete UnitTest.cs and replace BasicUnitTest.vstemplate with your modified copy
On the next run of Visual Studio you should see the modified UnitTest
Though you can do this for every default template, I recommend creating a new template based on the BasicUnitTest.zip instead of overriding the ones shipped with Visual Studio. It's easier, safer and won't be overwritten by future service packs.

Installing Visual Studio Project Templates without deleting the ProjectTemplatesCache

I'm working on an installer that needs to add several files to AVR Studio 5, an IDE developed by Atmel that is based on the Visual Studio Isolated Shell. These files include project templates for the "New Project" dialog.
By experimenting, I found that I can successfully add the project templates and get them to show up in the dialog if I simply copy them into C:\Program Files (x86)\Atmel\AVR Studio 5.0\ProjectTemplates\ and then delete or rename C:\Program Files (x86)\Atmel\AVR Studio 5.0\ProjectTemplateCache\cache.bin. I have not been able to find any good documentation on how the Visual Studio ProjectTemplateCache folder works. It seems to contain the same files as the ProjectTemplates folder, plus the cache.bin file, so I'm not sure why it would be useful. After I rename cache.bin, Visual Studio does not regenerate it, which makes me worried that renaming it might have some permanent consequences. Is renaming cache.bin a bad idea? What problems can it cause?
Is there another, easy way to install new project templates? Ideally I would like something that is easier than creating a Visual Studio Extension (.vsix) file, as recommended in this previous StackOverflow question: Installing a custom project template with Visual Studio Installer project
The installer I am working on uses NSIS, if that matters.
For my isolated shell I copy my template .zip files to 'Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates' and '\ItemTemplates'. I then run my isolated shell with the command line '/installvstemplates'. This rebuilds the caches and when you next run the isolated shell, they show up properly.
I also had to target the isolated shell in my extension manifest files.
Have you tried any of these?
If per user project templates are fine, you can drop them in <My Documents>\AVRStudio\Templates\ProjectTemplates.

Resources