How to fix TFS build with Visual Studio 2019 x64-bit - c#

MSBuild x64bit in Visual Studio 2019 works alright.
As executing MSBuild in Visual Studio, MSBuild locates:
C:\Program Files (x86)\Microsoft Visual
Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe
However, when running TFS Build, there is an error about "AxImp.exe" missing.
I am sure that I have Windows STKs installed when I installed Visual Studio.
Here is a snapshot of my .csproj property:
Project="$(MSBuildExtensionPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"
The TFS build agent resides on the same host having that same Visual Studio.
Here are the build definitions which are defined on TFS server:
MSBuild Version: Latest (or MSBuild 15.0 MSBuild 14.0 or MSBuild 12.0
or MSBuild 4.0)
MSBuild Architecture: MSBuild x64
When building the solution through TFS build, there is an error:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(2015,5):
Error MSB3091: Task failed becaused "AxImp.exe" was not found, or the
correct Mcrosoft Windows SDK is not installed. The task is looking
for "AxImp.exe" in the bin subdirectory beneath the loaction specified
in the InstallationFolder value of the registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft
SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86.
The log in TFS build shows that msbuild execution is located from:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe

Related

Blazor Server build error - new web application causes build errors

I recently installed Blazor as part of my Visual Studio Community 2019 version 16.3.2 installation. After creating a brand new Blazor Server web application in VS 2019 I have tried to run the app, only to get 3 errors in the build. The errors are:
Error: Project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Microsoft.Common.targets\ImportAfter\Microsoft.Web.ImportAfter.targets" was not imported by "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets" at (6101,3), due to the file being invalid. OktaBlazorAspNetCoreServerSide C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Microsoft.Common.targets\ImportAfter\Microsoft.Web.ImportAfter.targets
Error: Project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\Managed.Web\Microsoft.Web.Designtime.targets" was not imported by "C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk.Web.ProjectSystem\targets\Microsoft.NET.Sdk.Web.ProjectSystem.targets" at (42,5), due to the file being invalid. OktaBlazorAspNetCoreServerSide C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\Managed.Web\Microsoft.Web.Designtime.targets
Error MSB4024 The imported project file "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Microsoft.Common.targets\ImportAfter\Microsoft.Web.ImportAfter.targets" could not be loaded. Root element is missing. OktaBlazorAspNetCoreServerSide C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets
I haven't encountered MSBuild errors like this before and I need some directions. I am using .Net Core 3.0.100. If I use dotnet run from the command line the project runs as expected.
Updating Visual Studio Community 2019 to version 16.3.3 seems to have fixed this problem. I can create a new Blazor Server application and build and run with no errors, using DotNET Core SDK 3.0.100 on Windows 10. I guess the update must have contained the necessary bugfixes to finally try out this new product.
I had some odd issues with Blazor applications with Visual Studio 2019. I had been running the preview versions of Visual Studio 2019 and installed the release version on top of that. Completely uninstalling VS2019 and reinstalling fixed everything for me. Not a great solution, but it did resolve the weirdness I was having.

STARS.Web.csproj' targets 'net471'. It cannot be referenced by a project that targets '.NETStandard,Version=v2.0'

I am trying to publish a .csproj through the TFS Visual Studio Build task. When I Publish this project manually through Visual Studio 2017 it publishes correctly and everything works.
However we I run the build definition through tfs I am getting the following error:
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\MSBuild\15.0\Bin\amd64\Microsoft.Common.CurrentVersion.targets
(1656, 5) C:\Program Files (x86)\Microsoft Visual
Studio\2017\Professional\MSBuild\15.0\Bin\amd64\Microsoft.Common.CurrentVersion.targets(1656,5):
Error : Project '..\STARS.Web\STARS.Web.csproj' targets 'net471'. It
cannot be referenced by a project that targets
'.NETStandard,Version=v2.0'.
What am I doing differently between the TFS Build Task and publishing manually through Visual Studio 2017. Is there any way to check the steps both these process are doing? Both use the same publish profile.
TFS Build Definition Task:

Build succeeded with projects Ctrl + Shift + B that MSBuild can't build

Does anyone know where I can take a look at my project if after I make a build with MSBuild through MSBuild console I get this warning:
MSB4078: The project file 'MyProject.csproj' is not supported by
MSBuild and cannot be built?
My project is running with Target Framework .Net Core 2.0. The MSBuild version I am using is 14.0.25420.1
This is the cs.proj
You are using the new csproj file format (see Project sdk=...)
You will need to use MSBuild 15 in order for it to build. You have two options:
1) Download Build Tools for Visual Studio 2017 and install. Then the path will be:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin
2) If you have VS installed, the path will be:
C:\Program Files (x86)\Microsoft Visual Studio\2017\<VS Version>\MSBuild\15.0\Bin
Using MSBuild 15 should fix the error.
Please check what version of MSBuild are you running. I tested with the version 15.0, it runs without any error.
Generally, make sure that you have configured a build agent for your team project, and that you have Visual Studio 2017 installed on the agent machine and that you installed the latest Visual Studio update.
Also make sure you have select the MSbuild version 15.0 for the build.
See Build your ASP.NET Core app for details.
Reference this related thread: Support for .NET Core .csproj files
I suggest to use MSBuild in more reliable way.
Download Build Tools for Visual Studio 2017 from Visual Studio Downloads page, it includes latest MSBuild 15.* (direct link).
Command-line arguments documented here: Use command-line parameters to install
Visual Studio 2017.
All workloads and components are listed here: Visual Studio Build Tools 2017 component directory.
Use PowerShell module VSSetup to find MSBuild. Download it or install from here: Github: Microsoft/Visual Studio Setup PowerShell Module
Find MS Build
Import-Module $PSScriptRoot\VSSetup\VSSetup.psd1
$msBuildPath = (Get-VSSetupInstance | Select-VSSetupInstance -Version 15.0 -Product Microsoft.VisualStudio.Product.BuildTools).InstallationPath
if ([System.IntPtr]::Size -eq 8)
{
$global:msbuildPath = Join-Path $msBuildPath 'MSBuild\15.0\Bin\amd64'
}
else
{
$global:msbuildPath = Join-Path $msBuildPath 'MSBuild\15.0\Bin'
}
Write-Output "Using MSBuild from $global:msbuildPath"
Write-Output "MSBuild /version"
$msbuild = Join-Path $global:msbuildPath msbuild
& $msbuild /version

VSTS Online Building Setup Projects?

I have a .NET Console app with a setup project I am trying to port to VSTS Online (visualstudio.com) to make use of the source control and well as adding automated build/deploy.
I've got the code uploaded just fine and it builds great, but am struggling with getting it to produce a MSI. I've tried introducing a command line task after the solution build to run devenv.com but I can't quite get that to work. Any thoughts on getting a setup project to build its MSI?
Thanks!
EDIT:
Here's the command line task I tried:
Tool: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv
Arguments: SolutionName.sln /Build $(BuildConfiguration) /Project Setup\Setup.vdproj
EDIT 2:
New command line:
Tool: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.com
Arguments: MySolution.sln /Build $(BuildConfiguration) /Project Setup\Setup.vdproj
Logs:
2017-10-04T17:58:48.7033117Z ##[command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.com" MySolution.sln /Build release /Project Setup\Setup.vdproj
2017-10-04T17:59:12.1156461Z microsoft.visualstudio.telemetry.dll
2017-10-04T17:59:12.1196471Z microsoft.visualstudio.telemetry.dll
2017-10-04T17:59:12.1196471Z microsoft.visualstudio.telemetry.dll
2017-10-04T17:59:12.1196471Z microsoft.visualstudio.telemetry.dll
2017-10-04T17:59:12.1206475Z microsoft.visualstudio.telemetry.dll
2017-10-04T17:59:12.1206475Z microsoft.visualstudio.telemetry.dll
2017-10-04T17:59:12.1206475Z microsoft.visualstudio.extensionmanager.implementation.dll
2017-10-04T17:59:46.2231714Z
2017-10-04T17:59:46.2231714Z Microsoft Visual Studio 2017 Version 15.0.26730.3.
2017-10-04T17:59:46.2231714Z Copyright (C) Microsoft Corp. All rights reserved.
2017-10-04T17:59:46.2231714Z
2017-10-04T17:59:46.2231714Z Some errors occurred during migration. For more information, see the migration report:
2017-10-04T17:59:46.2231714Z d:\a\1\s\UpgradeLog.htm
2017-10-04T17:59:46.4634939Z ========== Build: 0 succeeded or up-to-date, 0 failed, 0 skipped ==========
2017-10-04T17:59:48.5239469Z ##[section]Finishing: Run C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.com
EDIT 3:
As per #Marina - MSFT I have tried the Build VS Installer, but it didn't quite work for me. The task competed successfully but it appears the MSI is never actually generated as nothing appears in the artifact drop. Here are the logs from the task:
2017-10-04T20:38:12.1314337Z ##[section]Starting: Create .msi file(s) from VS Installer project(s).
2017-10-04T20:38:12.1314337Z ==============================================================================
2017-10-04T20:38:12.1314337Z Task : DutchWorkz - Build VS Installer(s)
2017-10-04T20:38:12.1314337Z Description : Build .msi file(s) from VS Installer project(s).
2017-10-04T20:38:12.1314337Z Version : 1.2.4
2017-10-04T20:38:12.1314337Z Author : DutchWorkz B.V.
2017-10-04T20:38:12.1324342Z Help : <b>BuildVsInstaller v1.2.4</b>, DutchWorkz B.V. (Robin Paardekam)<br/><br/>Visual Studio Installer projects are not supported by MSBUILD, so a regular build will not generate your installer files (.msi). Use this build-task to build the .msi file(s) for your project by running devenv on the buildagent directly. <br/><br/><b>Dependencies:</b><br/>Dep1: when using VisualStudio 2017, this task will only function properly if you installed it in the default C:\Program Files (x86)\ location.
2017-10-04T20:38:12.1324342Z ==============================================================================
2017-10-04T20:38:15.3883721Z DEBUG: Aggregated: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\..\IDE\devenv.com
2017-10-04T20:38:15.4043950Z Now running (C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\..\IDE\devenv.com) with Arguments ("d:\a\1\s\MySolution.sln" /Build "release|any cpu" /Project "d:\a\1\s\Setup\Setup.vdproj" /Out "d:\a\1\b\BuildInstaller_Log_20171004203815.txt")
2017-10-04T20:39:39.8930682Z Done running DevEnv process. Success = True.
2017-10-04T20:39:39.8950669Z The single MSI should be located here: d:\a\1\s\Setup\release\
2017-10-04T20:39:40.0450669Z ##[warning]No .MSI files were found, please check your build-configuration. If this is expected, you might consider to use the default Visual Studio Build task instead of this custom Installer task.
2017-10-04T20:39:40.0560673Z ##[section]Finishing: Create .msi file(s) from VS Installer project(s).
Task config
To Build .msi file by VS installer project, you can use Build VS Installer task in marketplace.
You can specify to build .sln or .vdproj to generate .msi file(s) in Task-mode option.
You have to configure your own build agent to run the build since Visual Studio Installer Projects extension is not installed on the Hosted & Hosted 2017 Agent.
Make sure the VS Installer Projects extension is installed on your own build agent and then you can build the setup project either use command line task with "devenv" or use the "Build VS Installer" task.
And if you get the "8000000A" error like following:
Please following the instruction here to configure your build agent: Solution: An error occurred while validating. HRESULT = '8000000A'.
Then you should be able to build the setup project successfully:

Building VS Solution via command prompt

I have an solution with one project. Able to build it via VS GUI.
I want to build it via command prompt. But getting errors:
Command used:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" "C:\Users\xxx\Desktop\WebApplication1\WebApplication1.sln" /t:build
error:
error MSB4019: The imported
project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets"
was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
How to resolve this. Please suggest.
This can happen when Visual Studio is not installed on the machine on which you're attempting to build the project (e.g. a build agent).
Verify VS is installed, or if this isn't an option you could run the following command in the package manager console:
Install-Package MSBuild.Microsoft.VisualStudio.Web.targets
This package will update the .csproj file of your project to use the VS version of the targets if they exist, otherwise a local version contained in the packages folder.
The path of MSBuild should be "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" instead of "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe".
As per Visual Studio Blog: MSBuild is now part of Visual Studio!:
Starting with Visual Studio 2013, the 2013 version of MSBuild will ship as a part of Visual Studio instead of the .NET Framework. This transition allows us to more rapidly evolve MSBuild.
So when you build project via command prompt in Visual Studio 2015, the path of MSBuild should be "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe".
Hope this can help you.

Categories