MSBuild Issue with .NET 4.0 - msbuild

When I use msbuild on a .NET 4.0 project it appears to attempt to build the project with .NET 3.5. I've got Visual Studio 2010 installed and the project will build just fine in VS. It seems like an easy problem, but i'm kind of stuck.
So I use the command
msbuild
C:\ProjectPath\ProjectName.csproj
and I get the error.
Build started 9/30/2010 10:19:41 AM.
Project
"C:\ProjectPath\ProjectName.csproj "
on node 0 (default targets). Project
file contains ToolsVersion="4.0",
which is not supported by this version
of MSBuild. Treating the project as if
it had ToolsVersion="3.5".
ResolveAssemblyReferences:

Are you sure that MSBuild 4.0 is used? Launching MSBuild from commandline you should see :
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
If the right version isn't use, you'll have to launch MSBuild inside Visual Studio 2010 Command Prompt or put .NET 4 directory (%windir%\Microsoft.NET\Framework\v4.0.30128) in your path.

You are probably using msbuild.exe from the 3.5 directory. Instead use msbuild.exe under %windir%\Microsoft.NET\Framework\v4.0.30128. If you open a Visual Studio command prompt from VS 2010 start menu under VS Tools this path will be on your %path%.

Related

Visual Studio 2022 does not find reference assemblies for >NETframework Version 4.0

Trying to compile Python Django project but receiving build error:
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(1217,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
Done building project "myFinancialTracker.pyproj" -- FAILED.
How can I resolve?
I also got the same error as you, this is because VS 2022 doesn't come with
.net framework 4.0 option during installation, to overcome this problem I install VS 2019 and enable the usage of .net-framework 4.0 during installation. After the installation, I tried to run my project again using VS2022 and the error goes away.
I tried to download and install .net-framework 4.0 separately but Microsoft doesn't allow me to do so, to overcome this, I install VS2019 instead.

TFS build agent cannot find AXImp.exe

TFS build agent using MSBuild 14.0 fails with "Error MSB3091: Task failed because "AxImp.exe" was not found", while the SDK is installed and AxImp.exe is present.
The error states that it cannot find the file in the bin beneath "the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\NETFXSDK\4.6\WinSDK-NetFx40Tools-x86"
There is no "Microsoft SDKs" node at that location, however it does exist under Wow6432Node: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\NETFXSDK\4.6.2\
This node contains references to locations for both WinSDK-NetFx40Tools-x86 and WinSDK-NetFx40Tools-x64.
Is MSBuild looking in the wrong registry location?
Can I configure the build to make it locate either
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools
or
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\x64
to find AxImp.exe and whatever else it expects from the SDK?
Background:
Our development has so far been built on Windows 10, Visual Studio 2017, targeting .Net Framework 4.6.2. I am now trying to automate builds on Windows Server 2012 R2 Standard.
I have installed Microsoft Build Tools 2015, Microsoft .Net Framework 4.6.2 SDK, .Net Framework 4.6.2 Targeting Pack and .Net Framework 4.6.2 Targeting Pack (ENU).
Have successfully created a build agent and get an almost successful build, after chasing down a number of missing dependencies.
TFS build agent cannot find AXImp.exe
(According to the error messages, they are all common errors. we could not give the most direct correct answer for this issue, we can only give you some troubleshootings. In order to avoid losing contact in the round-trip comments, I post those troubleshootings as answer instead of comments.)
Make sure using the MSBuild task instead of Visual Studio build task in the build definition.
Using MSBuild 14.0 (C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe) rather than 4.0 (C:\Windows\Microsoft.NET\Framework\v4.0.30319) in the MSBuild task, if you build the project with Visual Studio 2015.
Check if the ToolsVersion of the Project node is 14.0 not 4.0:
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Install the Visual Studio 2015 on your build server.
Manually change the above registry key to the correct location, where AXImp.exe exists.
If all above not help you, please share the configuration of MSBuild task definition, the software you have installed on the build agent and try to build the project with Visual Studio 2015 on the build server.
Hope this helps.

Msbuild version in Framework vs Visual studio

Which version of build.exe is what?
I have a machine with Visual studio 2017 (v15) as only installation.
I then have 2 msbuild.exe files. One in the framework folder and the other in the Visual studio folder.
Besides different versioning, the output is different. The version number differs not only in format but in type of information too; Framework version vs Visual studio version. Without knowing better it looks like Visual studio has its own msbuild.exe, not deriving from the framework's.
C:\Windows\Microsoft.NET\Framework\v4.0.30319>msbuild /version
Microsoft (R) Build Engine version 4.7.3062.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
4.7.3062.0
vs
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin>msbuild /version
Microsoft (R) Build Engine version 15.6.85.37198 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
15.6.85.37198
A version of MSBuild was included in .NET Framework 4 which has not received any feature upgrades but since it is part of .NET Framework, it is continued to be shipped as part of Windows - frozen at the feature state that was implemented in version 4.0. The build number you posted indicates it is part of an 4.7.2 .NET Framework installation. It will only be able to build older .NET projects (Visual Studio 2010 c#/vb projects).
Newer MSBuild version are installed separately. Before Visual Studio 2017, there was a global MSBuild installation that VS used, but in 2017, MSBuild is local to the VS installation to support side-by-side installation of different VS versions.

WIX And NAnt : Unable to build WIX source code

I am trying my hands on source code of WIX 3.6 to debug something as well as learn something.
On executing make.bat (present in root folder of WIX source) file, first i got NAnt not found. So I downloaded NAnt and updated make.bat file. On executing the file again I am getting this error
NAnt 0.91 (Build 0.91.3881.0; alpha2; 8/17/2010)
Copyright (C) 2001-2010 Gerry Shaw
http://nant.sourceforge.net
Buildfile: file:///D:/wix36-sources/wix.build
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: inc
[readregistry] Registry Path Not Found! - key='Software\Microsoft\VisualStudio\VSIP\10.0\';hive='Microsoft.Win32.RegistryHive[]';
[readregistry] Registry Path Not Found! - key='Software\Microsoft\VisualStudio\VSIP\10.0\';hive='Microsoft.Win32.RegistryHive[]';
[property] Target framework changed to "Microsoft .NET Framework 2.0".
[property] Read-only property "dir.hhw" cannot be overwritten.
[property] Read-only property "hhw-found" cannot be overwritten.
BUILD FAILED - 2 non-fatal error(s), 2 warning(s)
D:\wix36-sources\wix.build(65,4):
Build file 'D:\wix36-sources\test\wixtests.build' does not exist.
I have .Net framework 4.0 installed on my local. Also I searched through registry for the registry key mentioned in the error and didn't found. Am I using right version of NAnt?
Do you have all of the prerequisites as described in the documentation?
In order to fully build WiX, you must have the following Frameworks and SDKs installed:
NAnt (0.90 or later)
The following components from the Windows SDK for Windows Server 2008 and .NET Framework 3.5, Visual Studio 2008, Microsoft Windows 7 SDK, and/or Visual Studio 2010:
x86 and x64 compilers, headers and libraries
IA64 headers and libraries are optional, but they are necessary for IA64 custom action support
If you want to be able to build optimized IA64 binaries, you'll need both the Windows SDK for Windows Server 2008 and .NET Framework 3.5 SDK AND Visual Studio 2008 installed; or the Microsoft Windows 7 SDK AND Visual Studio 2010.
HTML Help SDK 1.4 or higher [installed to Program Files or Program Files (x86)]
The missing registry key seems to be related to the VisualStudio SDK - you don't need this for basic WiX.
If you have all of the prerequisites, try passing the -debug switch to Nant for more detailed debugging output.
To solve this problem:
[readregistry] Registry Path Not Found! - key='Software\Microsoft\VisualStudio\VSIP\10.0\';hive='Microsoft.Win32.RegistryHive[]';
[readregistry] Registry Path Not Found! - key='Software\Microsoft\VisualStudio\VSIP\10.0\';hive='Microsoft.Win32.RegistryHive[]';
If you used Visual Studio 2010 SP1 you need Visual Studio 2010 SP1 SDK

How do I deploy a CLR Stored Procedure via the MsBuild command line?

I can deploy a SqlClr project project from Solution Explorer by right clicking it an selecting Deploy. However, I would like a command line version where I can also specify custom ConnectionString.
The command is msbuild MySqlClrProject.csproj /T:deploy. This assumes the code is built, and, at least on my machine, build the debug build by default. If you want to rebuild the solution, deploy the release binaries, and use a custom connection string, the command is msbuild MySqlClrProject.csproj /T:Clean;Build;Deploy /p:Configuration=Release;ConnectionString="Data Source=
.;Initial Catalog=dropme;Integrated Security=True"
You need to do this from a x86 2010 command prompt (MSBuild 4.0). It does not work in Visual Studio 2008 (MSBuild 3.5). I don't have Visual Studio 2012 to see if it works there.
If you attempt to run this from a 64 bit command prompt you will get the following:
c:\Users\jdearing\Documents\MySqlClrProject\MySqlClrProject.csproj(48,11): error MSB4019: The imported project "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SqlServer.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Below is an example of what running the command successfully looks like:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC>cd c:\Users\jdearing\Documents\MySqlClrProject
c:\Users\jdearing\Documents\MySqlClrProject>msbuild MySqlClrProject.csproj /T:deploy
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.261]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 7/11/2012 4:58:04 PM.
Project "c:\Users\jdearing\Documents\MySqlClrProject\MySqlClrProject.csproj" on node 1 (Deploy target(s)).
SqlClrDeploy:
Beginning deployment of assembly MySqlClrProject.dll to server . : dropme
The following error might appear if you deploy a SQL CLR project that was built for a version of the .NET Framework that is incompatible with the target instance of SQL Server: "Deploy error SQL01268: CREATE ASSEMBLY for assembly failed because assembly failed verification". To resolve this issue, open the properties for the project, and change the .NET Framework version.
Deployment script generated to:
c:\Users\jdearing\Documents\MySqlClrProject\bin\Debug\MySqlClrProject.sql
Dropping [MySqlClrProject].[SqlAssemblyProjectRoot]...
Creating [MySqlClrProject].[SqlAssemblyProjectRoot]...
The transacted portion of the database update succeeded.
Deployment completed
AfterDeploy:
---SqlReference---
Data Source=.;Initial Catalog=dropme;Integrated Security=True
Done Building Project "c:\Users\jdearing\Documents\MySqlClrProject\MySqlClrProject.csproj" (Deploy target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:09.37
c:\Users\jdearing\Documents\MySqlClrProject>