How to prevent Visual Studio 2017 from adding log files into solution? - visual-studio-2017

I have a C# .Net Core project and when I run this project the executable creates log file in it working directory which is same as project directory (where .csproj and other files are placed)
It is a rolling file, so every day it creates a new file with Date in the file name.
Problem is: Visual Studio adds this files into solution automatically:
How can I prevent this behavior? (This files are already in .tfignore file for TFVC but of course it has no impact on VS behavior).
UPDATE: I can exclude it from project manually but I don't like to do it every day.

I found solution:
Open your .csproj xml file
Add new section:
<ItemGroup>
<None Remove="log*.txt" />
</ItemGroup>
Enjoy you work!

Related

Visual Studio C++ Project File CustomBuild Task: Filter OutputItemType by File Extension

I have defined a custom build step in a Visual Studio 2019 C++ project file (.vcxproj) that generates .h and .cc files. There is a Custom Build Tool option entitled "Add Outputs to Item Type", where I can select one of "C/C++ header" or "C/C++ compiler". Is there some way to edit the resulting project file such that the .cc files are added as "C/C++ compiler" and the .h files are added as "C/C++ header"?
My intended work-around is to simply remove the generated .h files from the list of Custom Build Tool outputs. That work-around has the disadvantage that the build will fail if one of the .h files is missing or stale. I'm hoping for a solution that resolves this deficiency.
The following illustrates what I have attempted within the .vcxproj file:
<OutputItemType Condition="'%(Extension)'=='.cc'">ClCompile</OutputItemType>
Not sure about how you define the Custom Build Step. But custom build step is not the only way.
For C++ projects, msbuild provides Custom Build Tool, Custom Build Step, Build events and custom targets. You can achieve same requirements by this script:
<Target Name="CustomTarget" BeforeTargets="PrepareForBuild">
<Exec Command="xx.exe ..."/> <!--Call the tool.exe to generate files somewhere. We can save them in temp folder.-->
<Copy SourceFiles="xxx" DestinationFolder="xxx"/> <!--Use copy task to copy the generated files to project folder-->
<ItemGroup>
<ClCompile Include="Path of Temp folder\*.cc" />
</ItemGroup>
</Target>
And see this, I checked some related documents and confirm OutputItemType is something about ProjectReference. I'm not sure if this syntax supports other Items.

Creating visual studio template projects

I created a project template as described here: vs create template When I created a new project using the template, source files haven't added to project. I am using visual studio 2017 community edition. Actually source files (.h and .cpp) are visible in the solution explorer but they are not included in the project folder. So when I try to open them, ide gives me this message: "The document cannot be opened. It has been renamed, deleted or moved."
Is this a bug ? How can I fix it ?
It seems this is a bug. I solved it like this:
Visual studio automatically generates a .zip file containing the template project settings. However in that .zip folder, it doesn't include source files. I manually added every source files to the zip. Then I added fallowing lines to the automatically generated "MyTemplate.vstemplate" file.
<TemplateContent>
<Project File="yourProjectName">
<ProjectItem>source.cpp</ProjectItem>
.
.
.
</Project>
</TemplateContent>
and it worked.

Visual Studio Online, Pathing, C1083 and stdafx.cpp

So, I'm taking this class.... wince
My day job is pretty technical, but I'm a complete Visual Studio newbie.
I have a Visual Studio Express 2013 project that runs/compiles fine on my local system, but I have to get it to build in Visual Studio Online, so I can share it with the other people in my class.
The very first line of my program is:
#include "stdafx.h"
When I attempt to build my program in the online build environment, I get an error:
Error C1083: Cannot open source file: '..\..\..\..\..\path_to\file_on\my_local\computer\Project\stdafx.cpp': No such file or directory
The stdafx.cpp and .h files are in the project folder in source control, along with the main.cpp file, as well as showing up earlier in the build log when the project is cloned. But according to the #include directive docs the very first place it looks should be the directory where the main.cpp file lives?
Looking at the XML content of the .vcxproj filters files, I'm seeing an entry that looks like this for every file in the project:
<ItemGroup>
<Text Include="..\..\..\..\..\path_to\file_on\my_local\computer\Project\ReadMe.txt" />
</ItemGroup>
And I'm wondering if that's related, and/or somehow overriding the normal behavior of #include. However, I can't find a way to edit those from within Visual Studio (I mean, okay, I could open the file in Notepad++ or something, but that can't be the 'right' way... can it?)
So, is there a (preferably simple) way to tell my VS project to just look in "." for things?
In my case issue related to space is present between folder name, .sln path should not contain folder name with space, like 'foo foo', it should 'foofoo' or 'foo_foo'

How add existing file to Different Visual Studio Project Programmatically

I am newbie.
I want to create a Visual C++ project as programmatically.
I have tried EnvDTE objects but they are working on instance of current solution but I want to edit different project file of different solution that not opened anywhere.
How can I get instance of different project to edit it?
And I am using Visual Studio 2013 Express. Is there any limimation for it? Should I use VSPackage's?
Thanks.
In general I would recommend considering a build system like CMake or Scons. It allows to generate build scripts for arbitrary platform (as such it includes MSVS solution files).
However, you might simply edit project file with some script or program. Project files are plain xml files and it's easy to add external files.
<ItemGroup>
<ClCompile Include="some_file.cpp" />
</ItemGroup>

How does Visual Studio 2010 hosts MSBuild for C++ projects?

I have a solution with several C++ projects. For some of the projects I need some custom file copy, e.g. to copy some configuration files to the output directory or to copy the output files of one project to a specific folder after build.
In some cases I don't want or cannot add these files to the projects directly through the Visual Studio IDE. I created simple .targets files which I can reuse and add to the projects which need the file copying.
Here is a simple example .targets file for copying configuration files:
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDependsOn>
$(BuildDependsOn);
CopyCustom
</BuildDependsOn>
</PropertyGroup>
<ItemGroup>
<CustomFiles Include="$(ProjectDir)Config\**\*.xml" />
</ItemGroup>
<PropertyGroup>
<DestCustFolder>$(OutDir)Config\</DestCustFolder>
</PropertyGroup>
<Target Name="CopyCustom"
Inputs="#(CustomFiles )"
Outputs="#(CustomFiles ->'$(DestCustFolder)%(RecursiveDir)%(FileName)%(Extension)')">
<Message Text="Copy custom files..." />
<Copy SourceFiles="#(CustomFiles )" DestinationFiles="#(CustomFiles->'$(DestCustFolder)%(RecursiveDir)%(FileName)%(Extension)')" SkipUnchangedFiles="true" />
</Target>
</Project>
Through the "Build Customization" dialog in Visual Studio I add it to the project so it will be included like this at the end of the project file:
<ImportGroup Label="ExtensionTargets">
<Import Project="..\Targets\CopyCustom.targets" />/
</ImportGroup>
This should enable incremental build of my custom target. If I just edit one of my custom files (and none of the C++ files) and build it form the console with
msbuild foo1.vcxproj
it will actually detect the changes and does an incremental build for my custom target. If no changes are made the target is skipped.
If I do however build inside Visual Studio it will not detect changes to the custom files and only and gives me the message that the project is up to data:
========== Build: 0 succeeded, 0 failed, 5 up-to-date, 0 skipped ==========
I would have to additionally change one of the C++ files to make it check all targets again and to the incremental build.
I was expecting that Visual Studio just executes MSBuild which will then do the up-to-date check on the projects, so it should be the same result as running MSBuild from the console. I was trying to get more information by setting the verbosity level to diagnostic but I just get the same line. It seems to me that MSBuild is not even executed for the project but Visual Studio itself determines that the project is up-to-date.
So I was wondering how Visual Studio actually determines when it should execute MSBuild for a project.
I asked basically the same question before on the MSDN forum but couldn't get a clear answer.
See this suggestion on Microsoft Connect.
Basically you need to set DisableFastUpToDateCheck property to true to disable the fast-up-to-date check.
Just add to your vcxproj or your targets file:
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
I found an answer by looking into the book "Inside the Microsoft Build Engine, Second Edition".
Note: I also updated the same in my question in the MSDN forum but I will mainly duplicate the text here again for completeness.
On page 280 they actually saying that the IDE does a "fast up-to-date check" on the project-level. It only spawns a project build and does a more fine-grained check on the individual tasks if this rough project-level check fails.
When running MSBuild from the command line however there is always a fine-grained up-to-date check on the individual tools.
So the IDE only seems to do this fast check on the files which are added to the projects directly and set as one of the "Input File" types.
In my opinion this is not a good design. I would prefer that the IDE is only used to edit the MSBuild project files and then just invokes MSBuild to do the up-to-date check. This would make it much clearer.
I can understand that in a solution with a lot of projects it can make the up-to-date check much faster but there should be at least an option to disable the fast up-to-date check. I was checking the IDE if there is a way to disable this behavior but could not find anything.
The solution suggested here actually works and I am using it at the moment. But I added several custom targets for different kinds of custom files. If I add a new custom file I should never forget to set it to "Custom Build Tool" otherwise the incremental build for this file will not work.
I guess a solution would be to make a full build customization for my custom files and use specific file extensions for them so Visual Studio will automatically detect them when I add them to the project and sets the right Item Type.