Is there a way to get a VS project to build the debug EXE to a directory other than bin/debug?
I found this: http://msdn.microsoft.com/en-us/library/ms165410%28v=vs.80%29.aspx
However, that is only for the RELEASE not for debug.
UPDATE:
I failed to mention this is for the Express version, not the full version.
For anyone else who wants to do the same, here is how:
Open your '.csproj' file.
Find an element 'PropertyGroup' which defines the debug building process.
Then, inside you will find another element called 'OutputPath'. Just change the value of its text to the directory you want your debug output to go to.
To change the build output directory:
On the Project menu, click Properties.
Click the Build tab.
Click the Browse button next to the Output path box and select a new build output directory.
MSDN :Change Build output directory
.
The Output path is stored in the .cproj file. One for each configuration.
Open ur *project_Name.csproj* in any editor (say notepad)
For Debug:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
.....
<OutputPath>myOutput\</OutputPath>
</PropertyGroup>
Similarly For Release:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
...
<OutputPath>bin\Release\</OutputPath>
</PropertyGroup>
You could try manually editing the OutputPath.
The Output Path can take both Relative and Absolute paths.
Note: The Relative OutputPath should be relative to your project directory (project_Name.csproj) .
Related
I am trying to build a visual studio solution from the windows command line as follows:
msbuild solution.sln /t:Build /p:Configuration=Release
But I need to exclude a certain directory from one of the projects, and include another one. How do I do that?
Use this in your project csproj file:
<Compile Include="Folder1/*" Condition=" '$(Configuration)' == 'Release' " />
<Compile Exclude="Folder2/*" Condition=" '$(Configuration)' == 'Release' " />
Of course, you already set up the Configuration property, but you can replace it with your own property and set him from command line same as Configuration.
In the project dir, add two folders "CppFilesForDebug" and "CppFilesForRelease".
The "CppFilesForDebug" folder contains "Debug1.cpp,Debug2.cpp,Debug3.cpp" while "CppFilesForRelease" folder contains "Release1.cpp,Release2.cpp,Release3.cpp ".
Then add statement in the bottom of the vcxproj file like red rectangle below:
The red rectangle means we build and compile cpp files in "CppFileForDebug" folder when using Debug mode. And in release mode, we only compile cpp files in "CppFilesForRelease" folder insteat of cpp files in "CppFilesForDebug" folder.
I test it with C++ projects in VS2015 and VS2017 and it works. I think it can go well with your command "msbuild solution.sln /t:Build /p:Configuration=Release". Please it a try and any feedback would be great.
Update:
IF your issue results from QT conflicts, In vs, go QT menu ->Qt Project Settings->MocDirectory-> change it to
.\GeneratedFiles
Note: Don forget the "." before \GenerateFiles. Hope it helps. Any update you can share here.
I had a few minutes this morning to try to figure out why Visual Studio 2017 rebuild all of my projects in the solution every time I try to run the project. I think I know why this is happening but I'm not sure how to fix it.
I saw these articles:
http://michaelscodingspot.com/2017/04/28/visual-studio-keeps-rebuilding-projects-no-good-reason/
https://ofekshilon.com/2015/08/16/visual-studio-projects-that-just-keep-rebuilding-or-how-quantum-mechanics-mess-up-your-build/
Which got me to turn up build logging.
I now see that VS is looking for PDB files in the OBJ directory and since they are not there(1), VS thinks the project needs to be rebuilt.
3>Project '****.Common' is not up to date. Missing output file 'C:\*******\***\****.Common\obj\Debug\***.****.Common.pdb'.2>Build started.
1) The PDB files are not in the OBJ directory for the assembly projects. They are in the BIN directory. Note that in the main "executable" web project the PDB files are in both the OBJ and BIN directories.
So now I need to make visual studio do one of the following:
Put a copy of the PDB in the OBJ directory for all projects
Make VS check in the BIN directory for the PDB
I did some search but haven't been able to figure out a good set of search terms to find the answer to this one.
Note this is a project that has been developed using VS2012, VS2015, VS2017 and maybe some before 2012, so this might be part of the problem.
This was an issue with assembly project that had been created in older versions of Visual Studio (the projects created in VS2017 don't have the problem).
The workaround I found was to change this part of the .csproj file:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
<OutputPath>bin\Debug\</OutputPath>
...
</PropertyGroup>
to:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
<OutputPath>obj\Debug\</OutputPath>
...
</PropertyGroup>
Note that you can make this change in "Properties / Build" under "Output" by editing "Output path". Also note that this is apparently a workaround because I didn't need to do this to the VS2017 projects. If I go and exhaustively try to figure out the differences between the proj files, I'll update this answer.
There were a few other content items set to "Copy Always" which also forces the whole project to rebuild. I changed those to "Copy if Newer".
I can change the build path for a project in Visual Studio from the Project Properties dialog. But making a change to the .csproj file would interfere with the setup of other developers on the team, since this file is checked into source control.
So how can I change the build path so that this change only goes into the .user file?
Here's one way to do it:
In Visual Studio, make a change in the project properties.
Identify what changed in the .csproj file (using a diff tool)
Put that change into the .csproj.user file, making sure to include the xml structure.
Revert the change in the .csproj file so it remains unchanged.
Example of a changed path in a .csproj.user file:
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>..\..\..\CustomPath\</OutputPath>
</PropertyGroup>
</Project>
Background
I have an import process, which includes uploading a couple of files, which then go into an "Import" folder, the user then processes the files (get put into the database), which then get put into an "Archive" folder.
Problem
Running tests for this process, is where I'm encountering the problem.
The test import files for this are stored in a "Resources" (including Import and Archive) folder within the Tests project within the Visual Studio solution.
Current Solution: Attempt
A post-build event has been setup on the project to xcopy the "Resources" folder to the ${Outdir} - this works great in Visual Studio.
Problem
When I run Teamcity, the solution build - creates the folder (and subfolders) in /bin/Release/ rather than Teamcity's /out/ directory.
I'm sure I'm just not doing the copy in the correct way, there have been some suggestions of using MSBuild rather than xcopy, so could do with some help.
How do I setup Teamcity / my Solution to build to output these test files to the same place.
Using TeamCity
You can override the build output path by passing in the parameter to msbuild - this will override the project settings.
In the MsBuild / Visual Studio runner step, add this into the Command Line Parameters field
/p:OutputPath=out
The other alternative is to edit the project file in an editor and change the path there.
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>out\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
This will ensure that all files are output to a directory that is consistent whether you are building in Visual Studio or TeamCity
To get your test files into this directory, I would set the build action on them to Content and to copy if newer.
Hope this helps.
I'm getting an error in a VS2010 DB project that indicates I have too many charachters in my build path.
How can I change my default build path for all project types?
Something like
c:\build\$(projectname)\......
Thanks!
EDIT:
I've moved my project to the root of the C: drive and I still get the error with my DB project. I get this error when I try to right click the project and select properties
An error occurred trying to load the project properties window. Close the window and try again.
Cannot evaluate the item metadata "%(FullPath)". The item metadata "%(FullPath)" cannot be applied to the path "obj\Debug|Any CPU\TASS.DB.dbschema". Illegal characters in path. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets
The first thing that jumps out to me here is that your platform and configuration are being fused together to form "Debug|Any CPU" and a string is being made from that--the pipe is the character it's referencing there when it says there are illegal characters. I'm not sure how much your database project really differs with respect to debug/release and for architecture, but you may not even need to include them in the path.
Since you can't open the project property pages, you'll need to edit the msbuild directly by unloading it and selecting "Edit..." from the context menu (sorry if you know this already).
From there, assuming you're realling running up on the windows path length ceiling, you could use some msbuild trickery to maximize your headroom in there. Specifically, doing something similar to what you suggest: use the C:\ drive wherever possible.
To do this, look inside the PropertyGroups with the conditions for your Configuration & Platform configurations, and inside them replace the OutputPath and IntermediateOutputPath properties so that they're as short as possible, for example:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<OutputPath>$(SystemDrive)\D\A</OutputPath>
<IntermediateOutputPath>$(SystemDrive)\o\D\A</IntermediateOutputPath>
</PropertyGroup>
This saves some valuable characters in that instead of "Debug" you're using "D", "A" for "AnyCPU" and "o" for "obj".
Probably most importantly you're using C:\o\ for the intermediate build directory instead of C:\whatever-the-whole-path-is-to-your-project-file\obj. As well, this property isn't configurable from the property pages, from what I recall.
Some added flexibility there using SystemDrive instead of a hard-coded C:, not that I would really expect it to be different.
Finally, concerning your property pages load problem, I don't know how the Debug|AnyCPU got in your path (I don't know of any properties that store the concatenated flavor like that), but you should be able to pick it out pretty easily once you open up the file. Hopefully it's similar to load errors in something like the winforms designer where you change one line and suddenly the whole thing works again.
Hope this helps!
I don't think it's possible to set a default build path for all projects, only the standard Debug/Release folders within the project itself. The only suggestion I would have is to simply move the project folder to location with a shorter path.
EDIT: As per the new edit, have a look here:
http://connect.microsoft.com/VisualStudio/feedback/details/594333/database-project-template-files-corrupt
I updated a project from VS 2005 to VS 2010 and got the same error message.
"The item metadata "%(Filename)" cannot be applied to the path "obj\Debug|x86\Debug\DemoCSharp.pdb". Illegal characters in path." The problem is that Visual Studio 2010 fails in converting the csproj file to the new format, but it does not tell us where exactly the error is.
In my VS 2005 csproj file there is the following XML code:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">Debug|x86</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{05F88317-0CA7-4FE5-8520-35422402941A}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>DemoCSharp</RootNamespace>
<AssemblyName>DemoCSharp</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\output32\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>..\output32\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\output64\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>..\output64\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
Visual Studio does NOT tell us which line produces the problem. But I found it by "try and error".
The cause of the error message is clearly a bug in the Visual Studio conversion wizard because VS 2005 has no problem loading this csproj file while VS 2010 fails to convert it.
So you have to manually edit and fix this file and then load it anew in VS2010.
In my case the line that triggers the bug is the 3. line with <Platform Condition. The bug is that VS tries to take the value ("Debug|x86") of this platform condition XML node and embed it into a path on disk (like "...\obj\Debug|x86\..."). But as pipe characters are illegal in paths, it later complains and aborts the conversion.
So how to solve the problem ?
I simply replaced the third line
<Platform Condition=" '$(Platform)' == '' ">Debug|x86</Platform>
with
<Platform Condition=" '$(Platform)' == '' ">Debug</Platform>
which eliminates the pipe character and the project converted without errors.
NOTE: It is also possible to completely delete this line.
ATTENTION:
It is possible that in YOUR case the same error messages needs another fix than in my case. Please study the csproj file and look for the pipe characters, then find out with try and error how to modify it. This error can even appear in other conditions than converting a project.
But what they all have in common is that this is a Visual Studio bug (or in case of 'littlechris' a software extension bug) that tries to embed a pipe character into the path.
XML node: "Debug|x86" -> path "...\obj\Debug|x86\..."
I received this messeage because the absolute path of one of the files in my project exceeded 260 characters. Once I reduced the path length, I was able to build the project.