MSBuild building project and referenced project with same configuration - build

I'm using MSBuild to build a project with configuration set to a custom configuration. I have a referenced project (a library) which does not have any cutom configuration set to it. The issue is, it seems like MSBuild is building the project and the project references with the same configuration.
I'm using this command:
msbuild.exe <path>\<project>.csproj /p:DeployOnBuild=true /p:OutDir=<dirpath> /p:Configuration=<CustomConfig>
Im having the follow error:
C:\Program Files
(x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(724,5):
error : The OutputPath property is not set for project
'referencedProject.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this
project. Configuration='CustomConfig' Platform='AnyCPU'. You may be seeing
this message because you are trying to build a project without a
solution file, and have specified a non-default Configuration or
Platform that doesn't exist for this project. [path\ReferencedProjectcsproj]
I cannot find anything related online, if anyone can point me to anything or help me out with this, that would be great.

I found a work around, posting it here in case someone ends up in the same scenario.
The project library did not have the custom configurtation so, i had to edit the csproj file to change the condition of build configuration to this:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' Or '$(Configuration)|$(Platform)' != 'Debug|AnyCPU'">
This will force the compiler to take the leading configurations if it is in release mode or any custom configuration that is mentioned.
I have no found any way that will command MSBuild to choose different configuration project dependencies.

Related

The OutputPath property is not set for project (C++, blank new solution, VS2017)

It happens in a complex solution, but I can reproduce it in a new empty solution.
I built it (ctrl+shift+B) with debug mode, X86, diagnostic.
1> Set Property: _InvalidConfigurationMessageText=The OutputPath
property is not set for project 'ConsoleApplication1.vcxproj'. Please
check to make sure that you have specified a valid combination of
Configuration and Platform for this project. Configuration='Debug'
Platform='Win32'. 1> Set Property:
_InvalidConfigurationMessageText=The OutputPath property is not set for project 'ConsoleApplication1.vcxproj'. Please check to make sure
that you have specified a valid combination of Configuration and
Platform for this project. Configuration='Debug' Platform='Win32'.
This error may also appear in some other project is trying to follow a
project-to-project reference to this project, this project has been
unloaded or is not included in the solution, and the referencing
project does not build using the same or an equivalent Configuration
or Platform.
^ I make sure that there isn't any References that it claims.
Here is what I have tried.
First, a part of my .vcxproj (link to the full file) looks like this:-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
### I will insert something here ###
</PropertyGroup>
According to a SO link and another one, I should insert one of these lines at ### :-
<OutputPath>$(Configuration)\$(Platform)\</OutputPath>
<OutputPath>$(SolutionDir)$(Configuration)\</OutputPath>
<OutputPath>bin\$(Platform)\</OutputPath>
Same as above, but add it in <ItemGroup Label="ProjectConfigurations">
Remove Label="Configuration".
According to another SO link, I also tried AnyCPU or Any CPU (tested in a more complex solution, but a new empty solution doesn't have it.).
A Microsoft link states that Output Path is for C#. In C++, I must use Output Directory. It is OutDir.
<OutDir>$(SolutionDir)$(Configuration)\</OutDir>
<OutDir>$(Configuration)\$(Platform)\</OutDir>
Do above things, but in a property sheet.
Do above things, but also unloaded-reload project, and even restart VS2017.
After I tried every combination, the warning still exists.
The program can be compiled and run correctly,
but I believe it is a cause of unnecessary recompilation in a much larger solution.
Question: How to solve the warning/error?
OutputPath word in the console is suspicious.
I doubt VS recognize my solution as C#. (is it even possible? - my test project has std::cout)
For some reasons, most SO questions about this error are related to msbuild or C# or .net (another one), not C++.
Reply
There is no such Win32 option in the combo box, so I create a new one.
Configuration Manager > Active solution platform : <New...>
I also make sure that the setting is correct :-
However, I still got the same error message.
You have suspicious platform set - x86, change it to Win32.
UPD.: so the problem appears to be not with the project, but with Visual Studio installation - try to repair/reinstall it.
On my case, we moved the project from a different system, so, some of the directories were pointing to a wrong (non default) path.
On Solution Explorer, right click the project name, select Unload the project, then, right click again and select Edit the xxx.csproj, finally search, check and fix your <OutputPath>bin\Debug\</OutputPath> or <OutputPath>bin\Release\</OutputPath>on your different PropertyGroup conditions.

How to specify which .cpp files to compile based on the current build configuration?

I have multiple build configurations in my project, and I'd like to swap some .CPP files based on the currently selected configuration. How can I do that in Visual Studio 2013?
In the GUI, see properties of a cpp file and set "Excluded From Build" to yes for the configurations where it's excluded.
In the project file would look like:
<ClCompile Include="my_platform_specific_file.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
true
</ExcludedFromBuild>
</ClCompile>
In the IDE.
Select the configuration you want to alter (either from Build > Configuration Manager or the drop down in the toolbar. From the solution explorer, on the file you wish to; right click > Properties > Excluded from Build > Select Yes or No.
In the project file itself, locate the file being excluded
<ClCompile Include="xyz.cpp">
Add the following element;
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MyConfiguration|Win32'">true</ExcludedFromBuild>
Where MyConfiguration is the configuration you wish to exclude the file from.
This might be a good reason to start looking into more generic project managers.
I can recommend you looking into CMake , which is very powerful and can generate VisualStudio projects. The learning curve might be a high (for someone who is used to Visual Studio automation) but the gains are very high.
Some links:
Linking different libraries for Debug and Release builds in Cmake on windows?
http://cmaketools.codeplex.com/ - support for CMake files editing
http://www.youtube.com/watch?v=w9sKd8f0kFo - video displaying cmake integration into VisualStudoi
http://www.cmake.org/Wiki/CMake - random help
The project site is: http://www.cmake.org

Start debugging with Visual Studio from a different folder

I have a Visual Studio solution with set After-build commands. Those commands copy all files from the bin/Debug folder to the SOLUTION/Build/Debug folder.
Now I am trying to run debug from that SOLUTION/Build/Debug folder. Is that possible?
I have found in the Settings -> Debug -> Start External ... option, but this option won't accept a relative path to the executable (we need it relative as multiple developers are working on the project).
I have found a way how to do this.
First is needed to set in project properties Debug > Start External and Debug > Working directory to absolute paths. Then edit manually project file project.csproj.user and update it like this:
<StartAction>Program</StartAction>
<StartProgram>$(SolutionDir)Build\Debug\Prototype.exe</StartProgram>
<StartWorkingDirectory>$(SolutionDir)Build\Debug\</StartWorkingDirectory>
Then it is working as is needed.

Building VC++ 6 project from TeamCity. Can't find header files

I have a VC++ project and I have got the .dsw file. I want to build the project through TeamCity and obtain the .dll file.
In the TeamCity, In Build Steps I have given the Runner type as Command Line and passing in the following parameters.
Myproject.dsw /MAKE "Myproject - Win32 Release MinSize"
It creates empty output directories and all but I get this error
fatal error RC1015: cannot open include file 'afxres.h'
I have checked that the file is located at 'C:\ProgramFiles\Microsoft Visual Studio\VC98\MFC\Include'.
I don't understand why it is not picking up the file from this location. I tried adding this location to Environment Variable PATH, but it does not work.
The TeamCity picks up few files from 'C:\ProgramFiles\Microsoft Visual Studio\VC98\Include' though.
Please help.
I some how figured out the solution for this.
The TeamCity Agent runs as a windows service. So, it can not access the User environment variable for e.g. %include% and %lib%.
What I did is, I passed these two variables as environment variables to TeamCity Build. And voila!!! It works. :)

DeploymentProvider in manifest of ClickOnce depends on <Import Project=.. in project file

When I publish my project in VS2010 for ClickOnce a strange value for <deploymentProvider codebase="file://oldserver/.../....application" /> was present in my manifest file. The name oldserver name was wrong, it had to be replaced.
I didn't have a clue where the name oldserver came from?
In the project file I had
<InstallUrl>\\newserver\...\</InstallUrl>
but when opened, in the project properties in VS2010 oldserver was again displayed as publish folder location.
SOLUTION: In a hidden file called buildconfig.targets this was configured.
This file was referenced in the .proj file:
<Import Project="buildconfig.targets" />
In this file you need
<UpdateUrl>\\newserver\...\</UpdateUrl>
as well!
If you're publishing from Visual Studio, make sure you set the Install Url.
It's in the publish settings (in project settings for the project you are publishing) underneath the install url.
If you're publishing from MSBuild, then you need to set the UpdateUrl property (/p:UpdateUrl=youraddress for example).
When looking at your project in Visual Studio. select Build and then Configuration Manager. Check the information in your build configurations for Debug and Release and make sure they are correct. This is a total guess, but I could see something being set up in there.