I just set up a new project from this repository in Visual Studio Community 2015. Looking at the Solution Explorer, every single header file from this repository is included in the project.
However, opening a file (for example, atomic.h), will lead to most include directives being underlined in red with a mouseover-text cannot open source file "...". Continuing with the example file:
#ifndef ATOMIC_H
#define ATOMIC_H
#include "quantum.h" //underlined
#include <stddef.h> //not underlined
Yet the file is most certainly included in the project. It can be seen in the "Header Files" filter in the Solution Explorer. And it is included in the .vcxproj file:
<ItemGroup>
[...]
<ClInclude Include="quantum\quantum.h" />
[...]
</ItemGroup>
According to this answer, the inclusion of a file using the ClInclude tag should be enough to let IntelliSense find it, but it somehow doesn't seem to.
I can fix this by including every single folder and sub-folder separately in the VC++ Include Directories as mentioned here but that would take me hours. I also changed the double quotes to angled brackets, but that didn't help and I don't want to do that on a repo that I'm going to commit to either when it's working for everybody else.
Is there any way I can point IntelliSense to all the files that are obviously included in the project?
There's no need to build with MSVC, I only want IntelliSense to work properly.
I downloaded the example that you provided and got the same result like yours, from the .vcxproj file, the ‘ClInclude’ child element is under ‘ItemGroup’ element. This child element specifies the name of the header file for the C/C++ source file, we can know it from this, not means it will be auto complied.
We still need to add those parent folders of each #include "xxx.h" into the Node ‘AdditionalIncludeDirectories’ like you found. When you added it, then build and check the .vcxproj file, the addition include directory information should display like the following:
It will be a huge job to add those required folders into the Node ‘AdditionalIncludeDirectories’, you need to search the ‘xxx.h’ and find the record under ‘ClInclude’, copy the parent folder of this file and add into the node ‘AdditionalIncludeDirectories’ like the above, then reload the project and the intellisense works fine.
Related
I have a linked file in my csproj template:
<Compile Include="..\$saferootprojectname$\Shared Files\Mvx$saferootprojectname$.cs">
However, when the template is run, instead of leaving the relative path alone, Visual Studio substitutes the path of the temporary folder that is unzipped (and subsequently deleted!!!). The result is
> Error 1 Source file 'C:\Users\tim\AppData\Local\Temp\mi0qfyf2.5lc\Okra\Shared
> Files\MvxOkra.cs' could not be found \\vmware-host\Shared
> Folders\Documents\Projects\Temp\Plugins\Okra\Okra.Mac\CSC Okra.Mac
since the resulting csproj has
<Compile Include="C:\Users\tim\AppData\Local\Temp\k4psfgjk.22c\Crab\Shared Files\MvxCrab.cs">
<Link>MvxCrab.cs</Link>
</Compile>
instead of the relative path. Is there any way to solve this without resorting to a Wizard?
Update. This can be resolved by adding <CreateInPlace>true</CreateInPlace> into the vstemplate. Then the relative path ends up right. However, I do not want this solution. I would like the solution that allows CreateInPlace to be false (it seems to be default now in VS2012), because my solution is on a network share and it triggers a "do you want to open" prompt for every project in the template (there are 8). (Even when I say don't Ask)
Maybe an alternative solution would be how I can make a network share trusted so this prompt doesn't happen.
Usually, visual studio puts output files to bin/debug or bin/release.
When solution contains a large number of projects its not easy to modify each project output manually.
Also edits in csproj files no desirable, because some of them is shared between solutions..
My questions: Is anybody knows a tool, which can quickly configure output path ?
UPDATE: my problem solved by TFS Build
Presumably you have at least one project in each solution that is unique to that solution. In the Post-Build event of that, copy the contents of each project's output to the required location.
We often to this using a batch file. It's crude but effective. In our project that's unique to the solution we create a Release.bat file. This contains a number of file copies to copy all of the required components from the various output directories of the other projects. You can then just run the batch file in the post build event. We usually copy everything to a "Latest Release" fodler when the solution is built. If this becomes a proper release we will rename the Latest Release folder to the actual release number.
If you have multiple build configurations, or even just use the Debug and Release configurations, you can use an If statement in the Post-Build event to decide which batch file to run. So you could create a Debug.bat, Release.bat etc which do what you need. It can be tedious to set them up and get them working correctly at first, but they are very useful once fully implemented.
Customize your project using the msbuild properties which you can do if you follow these steps:
Go to the solution explorer and unload one project by right clicking on it and select Unload Project.
Then right click again on the unloaded project and select Edit Project. This will open the XML definition of your project, and you will have intellisense for the layout which will help you perform the next steps.
In the visual studio editor find the first PropertyGroup tag and add these lines near or at the end of the closing PropertyGroup tag:
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<BuildDirectory Condition="$(BuildDirectory) =='' or $(BuildDirectory) == '*Undefined*'">$(SolutionDir)\build\</BuildDirectory>
The above SolutionDir is defined in msbuild properties which you can obtain using this answer: msbuild script using solution information and also check out the well known msbuild properties here
The next step is to find the OutputPath tag for each configuration and edit it like this:
<OutputPath>$(BuildDirectory)\x86\AutomatedDebug\</OutputPath>
The example above assumes you have a configuration named AutomatedDebug with destination platform x86.
The output will be
x:\projects\whereever-your-solution-is\build\x86\AutomatedDebug\
Repeat for each project.
To unload more than one project, collapse all projects in the solution explorer and shift click or ctrl click to select all or some projects, then right click on the selected group to unload, unfortunately you cannot do this for editing, at least in visual studio 2010.
I am the first to admit that this is somewhat cumbersome to do for existing projects, but you could easily create a visual studio project template that has these settings changed so that new projects will use a more convenient default output directory.
You cannot edit the output directory directly in visual studio because the project properties editor escapes any $() enclosed text.
Also you could only modify the OutputPath using the name of a system environment variable enclosed in $(). This last option is to enable a global output directory.
If you build any single project modified in this way using msbuild directly in the commandline the output directory will be created one directory above from where you ran msbuild
..\build\x86\AutomatedDebug
If you are in a team, you should warn them not to edit the output directory directly by hand, as this action will overwrite any customization.
Hope this info is useful.
Greetings.
More specifically my problem is if I include a pdf in my project and set its build action to content so it gets copied to the server when I publish, is there a way to exclude it from visual studios search and replace feature. Would a post build action be a solution to this? I just don't want anybody to do a global search and replace in my project and mess up the pdfs...
I know I just said a mouth full so let me know if you need clarification. Thanks!!!
If you look in the section headed "Find options" in the find dialog, there is an option titled "Look at these file types". If you qualify the type as *.cs, it will only look in files with that extension. You can also enter multiple file extensions. As long as you don't include pdf files in that filter, it will not apply to them. An alternative is to define a folder set to search in by clicking the ... next to the folder combo. Put your PDF files into a sub-directory of your project and exclude that folder from the folder set.
Additionally, as you have said, not including them in the project and using a post-build event to copy them to the output would also work.
I would qualify though that you are trying to solve a problem that shouldn't really be a problem. The onus is on the developer doing a find and replace to take care in doing so, and to not replace the contents of files they don't intend to change in the first place. Find an replace can be a dangerous tool.
I've got a simple console project where I'm reading two Excel-files. The Excel-files are included in the project ("add existing item") and I've marked them with "Copy to Output Directory". However, they are not copied to the debug-directory when debugging/running the code.
I feel like I've forgotten something trivial. What do I need to do more?
In the file properties in Visual Studio, set:
Build action: None
Copy to output directory: Copy always
Changes to non-source code files don't cause a rebuild to occur - they aren't considered when the compiler does it's out of date checking.
Try forcing a complete rebuild by deleting your output directory completely (sometimes doing this from within Visual Studio isn't complete).
It may be that the files haven't been copied across because a full build hasn't been run.
None of this worked for my WPF project. You need to mark it Content + Copy Always.
Refer to this page for details on the different Visual Studio file properties.
Did you mark them as content?
I had an issue when some png files was renamed-excluded-added again to project. It seemed that VS2015 had lost tracking what to do with these files: although in VS the "Copy to output directory: Copy always" was set at the problematic files, CopyToOutputDirectory key was not present in csproj file. I had to change csproj manually from
<Content Include="xxx.png"/>
to this:
<Content Include="xxx.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Silly question but are you running in debug mode? I've made the same mistake and realised I was in release mode.
I put Content and Copy Always and it worked.
I just had this problem and for some reason choosing "Create application without a manifest" under the project's properties finally copied the linked content file to the build directory.
VS 2015 behaves similarly, not updating the output directory correctly with Content files. What does seem to work, strangely, is to put a text file in the folder with the Content files and make it a Content file also. The text file will get copied to the directory and so will all the other Content files. Stranger still, if you then delete the text file, it will continue to show up in the output directory even though there is no longer an original to be copied.
I'm programming in C++ on Visual Studio 2005. My question deals with .rc files. You can manually place include directives like (#include "blah.h"), at the top of an .rc file. But that's bad news since the first time someone opens the .rc file in the resource editor, it gets overwritten. I know there is a place to make these defines so that they don't get trashed but I can't find it and googling hasn't helped. Anyone know?
Add your #include to the file in the normal way, but also add it to one the three "TEXTINCLUDE" sections in the file, like so:
2 TEXTINCLUDE
BEGIN
"#include ""windows.h""\r\n"
"#include ""blah.h\r\n"
"\0"
END
Note the following details:
Each line is contained in quotes
Use pairs of quotes, e.g., "" to place a quote character inline
End each line with \r\n
End the TEXTINCLUDE block with "\0"
Statements placed in the "1 TEXTINCLUDE" block will be written to the beginning of the .rc file when the file is re-written by the resource editor. Statements placed in the 2 and 3 blocks follow, so you can guarantee relative include file order by using the appropriately numbered block.
If your existing rc file does not already include TEXTINCLUDE blocks, use the new file wizard from the Solution Explorer pane to add a new rc file, then use that as a template.
You want to Include Resources at Compile Time (MSDN).
Within Visual Studio IDE, right-click on the .rc file (in the Resource View panel), and select "Resource includes" from the shortcut menu. When the dialog opens, use its "Compile-time directives" area to enter whatever you want to include in the .rc file. For example, if you want your 64-bit and 32-bit builds to use different icons, you could include the appropriate resource file for each build as follows:
#ifdef WIN64
#include "Icons64.rc"
#else
#include "Icons32.rc"
#endif
It's worth noting that these defines are not set in the resource compiler by default, so for your 64 bit build make sure you add /DWIN64 to the rc build.
All the gory details can be found in MFC Technote #35.
-Ron
I'm not completely sure why you're trying to do, but modifying the resource files manually probably isn't a good idea.
I believe general practice for VC++ for globally-accessible values is to define them in stdafx.h (at least that's how I've seen it done), or to create something like a "globals.h" header file and include that wherever you need it. It really depends on what you're trying to accomplish though.