How do I convert or create .NET v3.5 solution in C++ VS2012 (specifically the toolset) - c++

I have a library that I need to use in VS2012 C++ solution that requires .NET 3.5. I understand that I can change the framework setting in project file but v90 tool set is not listed even though I have previous VS versions installed. Is there a manual process I can follow to allow this to occur?

Be aware: v90 is VS2008!!! You need v100 (V2010) or v110 (VS2012)!
If you want to change the .NET version, the you need to take a look at the following:
There is no option in the project settings to change this. You must manually edit the project file.
It is still not possible to change the target framework in the VS2010 or VS2012 IDE in the project settings.
The only way to change it, is to manually edit the vcxproj file. For this you need to do the following:
Right-click on the projectin Solution Explorer and select "Unload project"
The again do a right-click on the unloaded project in the Solution Explorer and select "Edit .vcxproj"
In the porject XML file search for the node "<PropertyGroup Label="Globals">"
In this node, find the sub node "<TargetFrameworkVersion>" (if it does not exists, you must add one)
The inner text of this node defines the target framework version. It can be one of the following values: v2.0,v3.0, v3.5 v4.0 or v4.5 (only VS2012)
Save the vcxproj Datei and close it
The again do a right-click on the unloaded project in the Solution Explorer and select "Reload Project"
Example:
<PropertyGroup Label="Globals">
<ProjectGuid>{089A9EBF-5149-462A-BC7E-2B1B59DE123C}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>CPP_VS2010</RootNamespace>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
See also: http://blog.kalmbach-software.de/2014/02/06/change-target-framework-in-ccli-for-vs20102012/

Related

Compiling Qt projects in Qt/MsBuild format without Qt VS Tools installed

I have many Qt projects in Visual Studio, using the new Qt/MsBuild format provided by the Qt VS Tools. When compiling in my development environment, where I have the Qt VS Tools installed, everything works flawlessly (compiling from IDE and from command line).
We have a computer dedicated to nightly builds, where only the compiler and msbuild are available (no IDE nor Qt VS Tools are installed).
When compiling the projects in such computer we get an error:
QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly.
Followed by several lines such as
e:********\Preferences.h(4): fatal error C1083: Cannot open include file: 'ui_Preferences.h': No such file or directory
(Project contains Preferences.ui).
How can I solve such errors when Qt VS Tools are not installed?
One solution provided by the Tools' creators is to copy %LOCALAPPDATA%\QtMsBuild into each project directory. But we are talking about hundred of projects. Doing manually, and more on, pushing them as part of the project itself doesn't sound very elegant.
One option would be to add a pre-build step that copies it from a common place into each project (and adding a **/QtMsBuild line to each .gitignore file). Again, looks like too much work.
When looking at the .vcxproj file for the Qt project you find this fragment (the reason for the solution provided by creators):
<PropertyGroup Condition="'$(QtMsBuild)'=='' or !Exists('$(QtMsBuild)\qt.targets')">
<QtMsBuild>$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
</PropertyGroup>
So, the simplest solution (without being able to install the tools), is to copy the %LOCALAPPDATA\QtMsBuild directory (from a system with the Tools installed) into the night computer (in any common place, but I decided to keep the location used by the tools) and then setting an environment variable:
set QtMsBuild=%LOCALAPPDATA%\QtMsBuild
PS: do not add double quotes to the variable (at least I had problems with them, so VS couldn't find the files).
Update 9-14-2020
I'm not sure on which version it started, but Qt projects created with (at least) the v2.5.2 Qt VS Tools fails to compile indicating that the Qt version has not been set. To solve so, you can
Copy the Registry entries from a computer with tools installed, located at HKCU\SOFTWARE\Digia\Versions.
If you will rely on a single Qt version (but that may be update globally for all projects), you can skip the Registry and just set the Qt version of all projects to $(DefaultQtVersion) (the same used in past project formats) and define an environment variable pointing to the directory of the version: set DefaultQtVersion=c:\Qt\Qt_5_15_0\Win32, for example.
I had problems in my case setting up $Env:QtToolsPath="$Env:QT_PATH\bin" fixed the problem. (It was not finding qmake for some checks). This, I think, is required when using QtMsBuild v3.3
Not sure if this info is 100% correct but may help someone.
For me to use MsBuild with Qt using QtMsBuild (not installing Visual Studio and/or VS plugins), I need to set up:
Example (PowerShell):
- $Env:PATH="$Env:MSBUILD_PATH;$Env:PATH"
- $Env:QT_PATH="D:\BuildTools\Qt\5.15.1\msvc2019_64"
- $Env:QtMsBuild="D:\BuildTools\Qt\QtMsBuild303" #303 Against visual studio project version
- $Env:QtToolsPath="$Env:QT_PATH\bin" #Support QtMSBuild , At desktop is done by the plug in
- $Env:PATH="$Env:QtMsBuild;$Env:PATH"
- $Env:PATH="$Env:QT_PATH\bin;$Env:PATH"
I hit this and got it working.
I followed #cbuchart 's advice; but needed to do a little more/different.
So here is what I did. I copied %LOCALAPPDATA%\QtMsBuild to my repo. I then edited my .vcxproj with a text editor. I adjusted the line that looks like:
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
To be:
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\..\QtMsBuild</QtMsBuild>
Depending on the relative location of where your project(s) are to the copied QtMsBuild directory you might want to adjust this. In my case the .vcxproj was in a directory one level from the directory that contains the QtMsBuild directory I copied.
Next in the QtMsBuild/Qt.props file I added the following:
<PropertyGroup>
<DefaultQtVersion>$(MSBuildThisFileDirectory)\..\Qt5.15.0\msvc2019_64</DefaultQtVersion>
<QtToolsPath>$(DefaultQtVersion)\bin</QtToolsPath>
</PropertyGroup>
That was added right after the opening Project tag in that file.
This was as #cbuchart mentioned something might have changed. I didn't do the Registry idea; but added those lines instead. I think it is possible to add them to a different file that gets imported before Qt.props if desired.
Now as for what this "Qt5.15.0\msvc2019_64" is; you'll need the tools, includes, libraries from a computer with Qt installed in order to build (also DLLs if your build needs to run the executable (i.e. tests)). This might be a lot of files so you can reduce it some if you know what you are doing. It might make sense to have these be put into it's own submodule or something.
After that it should uic/moc files and ultimately build (and run).
I got too. Maybe you need update your visual studio and then restart your computer ...
problem solved. reason: install 'qt vs tools' latest version but the visual studio
not support of it.

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

How to create a DLL with SWIG from Visual Studio 2010

I've been trying for weeks to get Microsoft Visual Studio 2010 to create a DLL for me with SWIG. If you have already gone through this process, would you be so kind as to give a thoughtful step-by-step process explanation? I've looked everywhere online and have spent many many hours trying to do this; but all of the tutorials that I have found are outdated or badly explained.
I have succeeded in going through this process with cygwin; but as some of you know, a cygwin DLL is not very practical.
As a result, I have .i, .cpp, and .h files that I know can create a DLL together. I just need to know how to do this with Visual Studio C++ 2010. The language that I am targeting is Python.
Step-by-step instructions. This assumes you have the source and are building a single DLL extension that links the source directly into it. I didn't go back through it after creating a working project, so I may have missed something. Comment on this post if you get stuck on a step. If you have an existing DLL and want to create a Python extension DLL that wraps it, this steps are slightly different. If you need help with that comment on this post and I will extend it.
Edit 8/19/2012: If starting with a C example, don't use -c++ in step 13 and use .c instead of .cxx for the wrap file extension in steps 14 and 19.
Start Visual Studio 2010
File, New, Project from Existing Code...
Select "Visual C++" project type and click Next.
Enter project file location where the .cpp/.h/.i files are.
For Project Name, choose the name used in %module statement in your .i file (case matters).
Select project type "Dynamically linked library (DLL) project" and click Next.
Add to Include search paths the path to the Python.h file, usually something like "C:\Python27\include" and click Next.
Click Finish.
Right-click the Project in Solution Explorer, Add, Existing Item..., and select your .i file.
Right-click the .i file, Properties, and select Configuration "All Configurations".
Change Item Type to "Custom Build Tool" and click Apply.
Select "Custom Build Tool" in Properties (it will appear after Apply above).
Enter Command Line of "swig -c++ -python -outdir $(Outdir) %(Identity)" (this assumes SWIG is in your path and redirects the generated .py file to the Debug or Release directory as needed).
In Outputs enter "%(Filename)_wrap.cxx;$(Outdir)%(Filename).py".
Click OK.
Right-click the .i file, and select Compile.
Right-click the project, Add, New Filter, name it "Generated Files".
Right-click "Generated Files", click Properties, and set "SCC Files" to "False" (if you use source-control, this prevents VS2010 trying to check in the generated files in this filter).
Right-click "Generated Files", Add, Exiting Item and select the _wrap.cxx file that was generated by the compile.
Right-click the project, Properties.
Select Configuration "All Configurations".
Select Configuration Properties, Linker, General, Additional Library Directories and add the path to the python libraries, typically "C:\Python27\libs".
Select Configuration Properties, General and set TargetName to "_$(ProjectName)".
Set Target Extension to ".pyd".
Build the "Release" version of the project. You can't build the Debug version unless you build a debug version of Python itself.
Open a console, go to the Release directory of the project, run python, import your module, and call a function!

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.