Finding all the visual studio projects a file belongs to - visual-studio

I'm working on a visual studio solution with over 30 projects and multiple filters.
What is the easiest way to determine all the projects a file belongs too?

First, open a command shell window and create a list of all project files in a text file. For example, for C# projects (having the ending .csproj), run this command in the root folder of your solution:
dir /s /b *.csproj >projectlist.txt
Then, you can easily determine all projects containing a specific file by the command
findstr /f:projectlist.txt /m Name_Of_Your_File
Just a suggestion: you can avoid much trouble for the future if you make sure each project has it's own folder, and all files belonging to that project are in or below that folder.

Use AgentRansack or similar tool that allows searching text contained in a file.
Use the following settings:
File Name: *.csproj
Containing Text: YourCodeFile.cs
Look in: YourSolutionFolder
Run the search and you will get a list of all project files that are holders of the CS file.

Related

Batch replacing Visual Studio Solution identifiers

I need to replace some identifiers in my solution, to avoid conflicts with external dependencies.
I used the Find and Replace dialog, setting the Entire solution as scope. It works, but it is too long.
One possibility could be:
forfiles /s /p path\to\solution /m *.cpp /C "sed -i 's/oldid/newid/g' #file"
Anyway, I have external include directories located in path\to\solution, which means writing the line above for every project directory (and of course including also *.h files).
Instead, VS GUI is smart enough to parse *.h and *.cpp files, excluding external dependencies.
Is there some (Visual Studio) CLI tool to list solution files, excluding external dependencies?

Visual Studio/TFS 2012 - Retrieve original filepath from .tmp files in comparison

I'm working on developing a specific comparison tool in Visual Studio 2012 with TFS 2012 installed, and am having trouble getting around TFS's use of temporary files for comparison. In Tools > Options > Source Control > Visual Studio TFS > Configure User Tools..., shown here:
I'm modifying the command for comparing .xml files, and TFS gives me the following options to add as command lines parameters to Powershell:
The issue is, I'm calling a custom Powershell script that will do some processing and determine what action to take based on the files that are being compared. However, some of the information required to process is the actual source control filepath of each file; which would appear to be stored in command line args %1 and %2. Unfortunately, TFS uses .tmp files to actually perform comparisons, so each of those paths points to the .tmp (stored in local AppData) file instead of the original .xml filepath that I need.
The contents of the files do not have the information I'm looking for, and the filepath is guaranteed to. Is there any way at all to use any other of the command line arguments provided by TFS to pass through the original filepaths to Powershell, or can I somehow tie back the .tmp files to the .xml path? I'm kinda stuck at this point. Thanks!
There is no option to specify the file in the argument. I've tested on my side with TFS2015 + VS2015, when added the PS tool to compare .xml file, it did compare .xml files, not .tmp file.
You can also specify the Source Path and Target Path when you compare the .xml files:

Utility to zip(archive) a solution?

Anyone know of a utility that exists which can traverse a solution file (.sln) and all of its project files and create a zip (archive) of that? My google-fu is failing me on this one, there are too many results showing how to write a program to zip files.
If you have 7zip installed, you can create a batch file to do what you want.
Create a file called archive.bat in the solution directory, open it and add:
"c:\program files\7-zip\7z.exe" a -tzip archive.zip * -xr#archive.ignored
Then create a text file called archive.ignored (in the same location as the .bat file) that lists the filenames/wildcards to be excluded from your archive.zip. For example:
obj
debug
bin
packages
*.obj
*.dll
*.exe
*.zip
*.suo
.vs
archive.ignored
archive.bat
CleanProject almost does what I want, but it doesn't actually read the .sln file so you need to have the relevant projects in the solution folder, and this grabs everything in those folders (cleaning up somethings you wouldn't want in the zip), whether they are referenced in the solution or not.
You should be able to accomplish that by creating a WinZip job. It's a one time setup where you define what, where, and when to create a zip file. I've used it to automate some backup tasks.

Output content file to specific folder while building project

I have VS 2012 project with structure like this:
Project
Folder1
file.xml
schema.xsd
code.cs
Folder2
code1.cs
code2.cs
I set Copy to output directory property of file.xml and schema.xsd to Copy always and want to output them to the same folder where assemblies outputed (bin\Debug) but they always copied to folder bin\Debug\Folder1. Is there a way to achieve my goal without moving files to the root of the project?
I recommend you do this with a Post-built event script. It's not as hectic as it sounds, and gives you loads of flexibility.
Right-click on your project and select Properties.
Go to the Build Events tab and click Edit Post-build...
(See screenshots below)
You can now specify shell commands to be executed after each successful build of your project. The following achieves the example in your question:
copy "$(ProjectDir)Folder1\file.xml" "$(TargetDir)"
copy "$(ProjectDir)Folder1\schema.xsd" "$(TargetDir)"
$(ProjectDir) and $(TargetDir) are macros which insert the respective values relevant to your project. You can select and insert macros from the macro menu in the edit window.
The quotes are included above, because your ProjectDir and TargetDir might resolve to full paths that include spaces, and that will break the copy command if the spaces aren't there.

How do I make sure every file in an included directory is copied to the destination in Visual Studio?

I'm building an application that has quite a few files that need to be included in the destination directory. So far, there haven't been very many files so I would simply change the settings of each file individually to Copy to Output Directory :: Copy if newer. The problem now is that I'm adding files at an exponential rate.
Do any of you know how to make all of the files that are sub of the "Some_Directory" have the Copy to Output Directory :: Copy if newer set how I want it?
You cam use a post-build event.
Using following posts, I made a post event that does exactly what you want:
Copying files into the application folder at compile time
Copy to Output Directory copies folder structure but only want to copy files
Visual Studio adds .dll and .pdb to project after compiling
Now, you can easily edit Post-build events, go to your project settings and go to the Compile tab, now click the Build Events and put following line in the *Post-build event command line" text box:
xcopy "$(ProjectDir)Test\*.*" "$(TargetDir)Test\\" /E /I /F /Y
See this image:
In your case you will have to change "Test" by "some_directory" and that's all.
There is one caveat, however. This copies every file every time my project builds. The folder that is being copied is over 3MB (I'm developing quite a large project). This makes debugging take quite a long time because every time I do a build it has to move all of the content over. Is there a way to make it only copy over files that have been updated since the last build? This is why I was using the Copy if newer option.
You can add the /D parameter (you can look that up with xcopy /? in your command prompt).
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
You can write your own custom Post-Build event (Select project -> Properties -> Build Events) with xcopy command. You can use $(solution) macro for your solution directory and specify relative path to your files.
I had the same issue, but the accepted answer didn't solve it. What worked for me was to enable deployment in Local.testsettings (under Solution Items).

Resources