Can Visual Studio read a set of include file paths from a text file for the Additional Include Directories? - visual-studio

I'm trying to figure out how to get Visual Studio to read a set of include files from a text file.
For example, I would like to create a text file called IncludePaths.txt that contains a list of include paths such as "/I ../../header"
I would then tell Visual Studio reference this file.
I believe you could do this by adding #IncludePaths.txt to the Additional Include Directory, but I cannot get this to work. I have seen this done in projects I have worked on in the past but I can't find any documentation or figure out the trick.

After a little more research and talking to a couple of other developers, I figured out the "trick"
1) Create a file called IncludePaths.txt next to my project file.
2) Add your include paths to this file...
/I "..\..\..\..\open\common\include"
/I "..\..\..\common\include"
/I "..\..\"
3) Go to Properties -> C++ -> Command Line
4) Under "Additional Options" add #IncludePaths.txt
Alternatively, you can use custom properties to get this to work too.

Related

How can I exclude these folders and files when searching a very large Visual Studio project?

I am trying to search a very large application with hundreds of folders and thousands of files using the Visual Studio "Find in files" feature. I want to search all C# files (*.cs) excluding:
View*.cs
*\UnitTests\*.cs
*\Archive\*.cs
I found How do I tell Visual Studio to exclude folders from the Find in Files? and responses, but due to the size of the application, adding each folder is not workable, nor is unchecking "Search subfolders":
New folders are added frequently so I'd rather have an exclude list instead of an include list so I don't miss anything.
Is there a "Not" operator syntax for file types? I tried ^, !, and | to no avail.
Did you try Ctrl + Shift + F which will give you following option.
In the search window you can select which folders to include in the search.
Alternatively if you have Git Bash installed and if your project is a git repo then easiest way is to use following command. I tested it with my project and it works fine with sub folders as well.
git ls-files -- '*.cs' ':!:*Test*.cs'
This will include *.cs file but exclude anything like *Test*.cs. You can change the pattern as per your requirement.

code reuse for file existence test in a Visual Studio vcxproj file

I have a vcxproj file that contains explicit Windows shell commands in the NMakeBuildCommandLine section:
<NMakeBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
move file1 file2
</NMakeBuildCommandLine>
I'm using MSBuild to execute the vcxproj, either directly or via a sln file. The problem is that when file1 does not exist, the output is very unhelpful and doesn't even list the file's name:
The system cannot find the file specified.
My naive solution is to replace move file1 file2 with:
if exist file1 (move file1 file2) else (echo file1 does not exist && exit 1)
(Note that I need to write && instead of &&.)
This works, but it's error-prone because I need to type file1 three times per line and make sure they all match. file1 is only one of many files that need to be moved. Furthermore, the series of commands is virtually identical across the various build configurations.
How can I avoid repeating myself both within a command line and across build configurations? I thought that the UserMacros property group might help me, but I couldn't figure out how to write such a macro via the IDE. (Right-clicking on the project in Visual Studio doesn't show a field for entering user macros.) Nor could I find any discussion of the syntax of this section on the Internet, so I didn't know how to write macros with a text editor (which I would actually prefer).
There may be yet a better way within a vcxproj file to identify files that need to exist, so I'm open to any alternatives.
MsBuild has 'variables' like most other programming languages called properties. You declare one in a PropertyGroup element in the project file xml and then reuse it using the $(PropertyName) syntax. Example for your case:
<PropertyGroup>
<Src>/path/to/my/src</Src>
<Dst>/path/to/my/dst</Dst>
</PropertyGroup>
<NMakeBuildCommandLine>
if exist $(Src) (move $(Src) $(Dst)) else (echo $(Src) does not exist && exit 1)
</NMakeBuildCommandLine>
If you want to use the IDE, which might get tedious if you have lots of values, you can indeed use so-called UserMacros but you have to declare those in a proprty sheet. Go to View->Property Manager, right-click on your project and select 'Add new Property Sheet'. Doubleclick on it, go to 'User Macros' and add key/value pairs there. If you save everything and look in the generated files you'll see the vcxproj now Imports the propertysheet, and the propertysheet itself has a PropertyGroup just like shown above - but editable thgough the IDE.
As an alternative which might be better (less duplication, easier to automate) in the long run you can use MsBuild code for checking file existence and moving files which has the benefit you only have to write the move command once as you can have MsBuild loop over items. Those are declared in an ItemGroup. Explaining everything here is a bit out of scope but an example should make things clear:
<Target Name="BatchMove">
<ItemGroup>
<SrcFiles Include="file1">
<Dest>file2</Dest>
</SrcFiles>
<SrcFiles Include="file3">
<Dest>file4</Dest>
</SrcFiles>
</ItemGroup>
<Warning Text="Source file %(SrcFiles.Identity) does not exist" Condition="!Exists(%(SrcFiles.Identity))" />
<Move SourceFiles="%(SrcFiles.Identity)" DestinationFiles="%(SrcFiles.Dest)" Condition="Exists(%(SrcFiles.Identity))" />
</Target>
This declares 2 source files file1/file3 and their respective destination files file2/file4. If the source does not exists (using standard MsBuild Exists check) a message is shown, else it is moved to the destination. Those % characters will make the line they occur in loop over each element of the SrcFiles collection. To add more files, just add to the ItemGroup. Last step is to get this target invoked from the nmake command line which is done simply by calling msbuild on the file itself and telling it to run the target:
<NMakeBuildCommandLine>
msbuild $(MSBuildThisFile) /t:BatchMove
</NMakeBuildCommandLine>

Creating empty directories / folders in InstallAnywhere 2011

I have a script which collected together a number of files to be installed. This includes a number of empty directories.
Previously I would use the D flag in the manifest file which would copy empty directories. However due to the way I generate the manifest files (as part of our build process) I can sometimes end up with two D entries with the same destination folder. e.g:
D;${A_LIB}/all/pysys/${PYSYS_VERSION}/lib/python2.7/site-packages;./third_party/python/lib/python2.7/site-packages;COMMON;${UNIX}
D;${A_LIB_BT}/python/${PYTHON_VERSION};./third_party/python;COMMON;${ALL}
This causes InstallAnywhere to fail to build the installer.
To get around this I rewrote the manifest generation code to parse the directories previously pointed to by a D and replace the D entry with F entries for each file in the directory.
Unfortunately this will not include empty directories (which we may / may not need in the installer but in general it's just safer to create them than have some piece of code fail because they're not there).
I've tried the following in the manifest. Reference, Reference3 and Reference4 are empty, Reference2 contains a single directory (which is itself empty). Only Reference2 is present in the install - the other three which are empty directories seem to get excluded.
D,$IA_PROJECT_DIR$/samples/pysys/cor_002/Reference,./samples/pysys/cor_002/Reference
D,$IA_PROJECT_DIR$/samples/pysys/cor_002/Reference2,./samples/pysys/cor_002/Reference2
D,$IA_PROJECT_DIR$/samples/pysys/cor_002/Reference3/.,./samples/pysys/cor_002/Reference3/.
D,$IA_PROJECT_DIR$/samples/pysys/cor_002/Reference4/../Reference4,./samples/pysys/cor_002/Reference4/../Reference4
I've also tried increasing the log level but this has not revealed anything. Is there a way to increase this log level?
export LAX_DEBUG=true
Any suggestions?
DISCLAIMER: I've cross posted this to InstallAnywhere's forums but I will do my best to keep the answers in sync and spread the knowledge.
I can't speak to your manifest challenges. However, my first thought is to change the manifest generator to be sensitive to duplicate output locations -- maybe by storing them in a Map or Set -- and then handling collisions when they occur by failing the build or adjusting the output location(s).
On the other hand, I can tell you how to increase the verbosity of your installer.
Make the installer more verbose by adding:
-Dlax.debug.all=true -Dlax.debug.level=3
to Project > JVM Settings > Installer Settings (tab) > Optional Installer Arguments > Additional Arguments. You'll want to remove these before you ship. You can also add these to the command line when you start the installer. Level values of 4 and 5 work, too, and are even more verbose.
You can also make your installer print its progress to the console by going to Project > JVM Settings > Log Settings. Here, uncheck Include debug output (stderr and stdout). Then enter the word console in Send stderr to: and Send stdout to:. Rather than console, you can also set a specific file name. You'll also want to undo these settings before you ship.
The solution turns out to be so blindingly simple that I never tried it.
To get EMPTY directories installed by Install Anywhere you have to specify the directories as files in the manifest. So with the following directory structure:
Reference <empty>
Reference2
testdir <empty>
Reference3 <empty>
Reference4 <empty>
You need to specify the entries in the manifest as F. Specifying then as D will only result in the "Reference2" directory being included.
F,$IA_PROJECT_DIR$/samples/pysys/cor_002/Reference,./samples/pysys/cor_002/Reference
F,$IA_PROJECT_DIR$/samples/pysys/cor_002/Reference2,./samples/pysys/cor_002/Reference2
F,$IA_PROJECT_DIR$/samples/pysys/cor_002/Reference3/.,./samples/pysys/cor_002/Reference3/.
F,$IA_PROJECT_DIR$/samples/pysys/cor_002/Reference4/../Reference4,./samples/pysys/cor_002/Reference4/../Reference4
Sorry to answer my own question, really wasn't the plan!

User VisualStudio PostBuild with place-marker

After successfully build, I want to copy the content of the the folder to the destination.
I've learned that this will work fine:
copy "$(TargetPath)" "$(TargetDir)\..\..\..\TB-Annotation Editor\bin\Debug\Plugins\$(TargetFileName)"
But I am interested to copy all *.exe, all *.dll and all *.txt files into the destination and this could cost a lot of lines for each plugin. Now I wanted to ask if there is any possibility to use place-marker instead of fixed filenames.
this does not work and raise event "Error Code 1"
copy "$(TargetDir)*.*" "$(SolutionDir)bin\Debug\plugins\"
Regards
** Solved except .dll *
I'm very sorry, seems to be not an error because of the "*" but of the folder which is called same twice:
copy "$(TargetDir)*.*" "$(SolutionDir)MyProject\bin\Debug\plugins\"
Goes correct to:
"copy
"C:\Daten Laptop\PAG\Net\MyProject\Solution\Plugins\DSP - Alphablend\bin\Debug\DSP - Alphablend.exe"
"C:\Daten Laptop\PAG\Net\MyProject\Solution\MyProject Main\MyProject Main\bin\Debug\plugins\DSP - Alphablend.exe""
But when using ".dll" instead of ".*" (DLL does not exist, because at the moment it is selected as *.exe) it does throw error code 1 again.
To my mind the best way of doing this is setting file properties and project properties. This requires no additional lines at all. If you set "output folder" property for project, "copy local" flags for referenced libraries and change "Build action" and "Copy to output directory" properties for your txt files (they should be included to solution) you get what you want.

How can I make Textmate always ignore the /log folder in the "Find in Project" search?

How can I make Textmate always ignore the /log folder in the "Find in Project" search?
Add the log folder to the excludeInFolderSearch option in your ~/.tm_properties file, e.g.:
excludeInFolderSearch = "{$excludeInFolderSearch,$extraExcludes,log}"
I found a easier way to do it.
Go to Settings > Advanced > Folder References
And add |log| to the pattern.
valid for TextMate 1
Other answers did not work for me on TextMate 2.0-beta.12. After many frustrating attempts, this line was able to exclude the log, vendor, tmp and .git directories from fuzzy searching.
excludeInFileChooser = "{$excludeInFileChooser,log,vendor,tmp,.git}"
I added this line to a .tm_properties file in my project directory. I verified that this also works if you decide to put the .tm_properties in the home directory.
Edit:
Use excludeInFileChooser for modifying search paths in Textmate's "Go To File" navigation feature, which is activated by ⌘T.
Use excludeInFolderSearch for modifying paths when searching for text within the files of a directory, which is activated by either ⌘F or ⌘↑F
None of these worked for me. What worked was adding the following in a .tm_properties file (project root)
excludeDirectories = "{node_modules,}"
No $exclude variable. Add trailing comma.
For Textmate 2:
Click on the top menu Textmate, then Preferences.
Navigate to the second tab, called Projects.
On the "Exclude files matching" just add 'log' to the end of the list, for example:
{*.{o,pyc},Icon\r,CVS,_darcs,_MTN,\{arch\},blib,*\~.nib,tmp,log}
This should do it, the log folder should no longer be searched, or used as match when opening a file.
Use AckMate, https://github.com/protocool/AckMate and read hot to change the normal Find in Project Shift+Cmd+F here github.com/protocool/AckMate/wiki/Usage
Alternatively you could explicitly tell Mate to look at a specific subset of folders.
~/project/mate app db models
Project find will be restricted to those folders.
Or to just remove the log dir you could add an alias to ~/.profile:
alias m="ls | grep -v 'log' | xargs mate"
Just remove reference to log folder from project tree.
Also you may right click on *.log files and mark then as binary (they will not be searched).
http://wiki.macromates.com/Troubleshooting/FindInProject
For TextMate2 it should be: excludeDirectories = "{$excludeDirectories,log}"

Resources