When I try to build my .csproj file with dotnet it throws an error, but when I build project at Visual Studio 2019 it succeeds.
I need to build with dotnet because my Azure pipeline job uses it.
This is the error:
dotnet build MyProject.Mobile.Droid.csproj --configuration Release --force
MyProject.Mobile.Droid.csproj(584,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.100\\Xamarin\Android\Xamarin.Android.CSharp.targets was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.100\\Xamarin\Android\Xamarin.Android.CSharp.targets" is correct, and the file exists on disk.
Build FAILED.
(Also as a screenshot.)
If I set the path parameter in my .csproj to this:
<MSBuildExtensionsPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild</MSBuildExtensionsPath>
Then the error changes:
The reference assemblies for MonoAndroid,Version=v1.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
Any suggestions on how to solve this?
You'll need to use msbuild (like msbuild MySolution.sln) to build a Xamarin project today.
You can build the individual netstandard2.x projects using dotnet build, however the Mono based platform projects (i.e. the Android and iOS projects) need to be built using msbuild.
Try setting the TargetFrameworkRootPath to where you have xamarin installed.
<TargetFrameworkRootPath>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\</TargetFrameworkRootPath>
or on the command line
dotnet build -clp:ErrorsOnly -p:MSBuildExtensionsPath="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild"/ -p:TargetFrameworkRootPath="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/ReferenceAssemblies/Microsoft/Framework/"
Related
Whenever I try to build any documentation using docfx, I get the following error in the metadata build step that uses msbuild to analyze the xml comments in the code of the csprojs:
Warning:MetadataCommand.ExtractMetadataWorkspace failed with: [Failure] Msbuild failed when processing the file 'C:\temp\docfxtest\docfx_project\src\src.csproj' with message: Could not load SDK Resolver. A manifest file exists, but the path to the SDK Resolver DLL file could not be found. Manifest file path 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\SdkResolvers\Microsoft.Build.NuGetSdkResolver\Microsoft.Build.NuGetSdkResolver.xml'. SDK resolver path: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet\Microsoft.Build.NuGetSdkResolver.dll C:\temp\docfxtest\docfx_project\src\src.csproj
It seems that msbuild cannot be correctly resolved by docfx. Any idea how I could fix this?
Im using docfx version 2.56.5.0 on Windows and I also have VS Enterprise 2019 (16.8.2) and VS Build Tools 2017 (15.9.29) installed:
UPDATE:
I have now uninstalled the VS 2017 build tools completely and repaired the VS 2019 installation using the installer. I now get a different error when I run docfx. It seems that it can't find msbuild at all anymore.
Warning:MetadataCommand.ExtractMetadataWorkspace failed with: [Failure] Msbuild failed when processing the file 'C:\temp\docfxtest\docfx_project\src\src.csproj' with message: The SDK 'Microsoft.NET.Sdk' specified could not be found. C:\temp\docfxtest\docfx_project\src\src.csproj
Running msbuild -t:restore,build also shows that it can't find msbuild
'msbuild' is not recognized as an internal or external command
The targets are isntalled:
And so is the .NET Core workload:
Your Build Tool for VS2017 might have some problems due to some issues. The most issue is this:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet\Microsoft.Build.NuGetSdkResolver.dll
Either you lost the dll or the dll is damaged.
Update
1) First, you should check whether you have installed NuGet targets and build tasks workload and net core build tools workload. If not, please install it.
2) Second, please delete bin and obj folder of your project and then try again.
You should use msbuild -t:restore,build to build your project.
3) Third, try to Repair from vs_installer for your build tool. It will repair the related dll. And then delete bin and obj folder, use build tool to test your project again.
Important:
VS2017 does not support net core 3.1. You should note that. It supports <=net core 2.1.
So if you still want to use Build Tool of VS2017 for your net core project, you should try the the above three steps and then target your project to net core 2.1.
Besides, if you start msbuild by CMD, I think you should check your environment variable PATH and check whether you have configured the msbuild.exe from Build Tool of VS2017 on it. Instead, you could add C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe. This way is for VS2019.
=================================================
Update 1
The problem is that you have already installed a docfx tool by choco command line.
At the beginning, I always thought that you used docfx.console nuget package on your project and just invoke docfx.exe from C:\Users\xxx\.nuget\packages\docfx.console\2.56.5\tools\docfx.exe under command line.
Regardless of the installation of docfx.console package on your project, if you installed docfx tool by choco command and then just invoke docfx.exe on command line, it used the local docfx.exe under C:\ProgramData\chocolatey\lib\docfx\tools\docfx.exe rather than the nuget package.
So the issue is that your local docfx.exe has some errors due to some issues. You should reinstall the docfx.exe by choco command choco uninstall docfx; choco install docfx.
Actually, directly use docfx.console nuget package on your project might be easier. From this link.
It already contains the generation step of the documentation by docfx.exe(from C:\Users\xxx\.nuget\packages\docfx.console\2.56.5\tools\docfx.exe) and will execute it automatically rather than run docfx.exe again manually.
I have completely uninstalled docfx using chocolatey (choco uninstall docfx) removed every folder named docfxfrom c:\ProgramData\chocolatey\.chocolatey\ and then reinstalled it (choco install docfx). After that, everything worked fine again. The file c:\ProgramData\chocolatey\lib\docfx\tools\docfx.exe.config contains a lot of msbuild related configuration. Maybe something was messed up there.
So, I have a .csproj file that is targeting .NET Standard, .NET Core and .NET Framework: https://github.com/dhilgarth/ReadGitVersionInformation/blob/master/src/ReadGitVersionInformation.csproj
I want to create a NuGet package from that project file and are therefore running the following command inside the folder which contains the project file (this folder is named src):
NuGet.exe pack ReadGitVersionInformation.csproj
The result of this command line is this:
Attempting to build package from 'ReadGitVersionInformation.csproj'.
MSBuild auto-detection: using msbuild version '15.7.179.6572' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'.
Error NU5012: Unable to find 'bin\Debug\src\bin\Debug\'. Make sure the project has been built.
It is looking for the nonsensical pack bin\Debug\src\bin\Debug.
What am I missing here?
Use dotnet pack to pack SDK-based project files. (e.g. dotnet pack -c Release)
nuget.exe pack is used only for legacy csproj files.
I am trying to figure out how what to install to get nuget.build.tasks.pack.targets installed for msbuild.
My CSProj files use MSBuildSDKsPath macro and that is resolving to
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Sdks\
But I don't have the SDKs directory. I have
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild
/Microsoft
/15.0
What do I need to install to get it?
The pack targets are not wired in for csproj based .NET Framework projects.
Only .NET SDK has the pack targets imported by default. Specifically the new SDK projects that are PackageReference based.
To use the pack target with the old csproj you need to install the NuGet.Build.Tasks.Pack package.
You can get it from nuget.org.
Make sure you set PrivateAssets=all
Recently, I converted an Azure Function that used a C# script (*.csx) to a pre-complied class library using the Visual Studio Studio Tools for Azure Functions. It builds successfully in Visual Studio 2017 (as well as running and debugging too).
I'd like to build this AF library via our CI process. However, when I run the command dotnet build locally it fails with the following error:
C:\Users\ray\.nuget\packages\microsoft.net.sdk.functions\1.0.2\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(31,5): error : Could not load file or assembly 'Microsoft.Azure.WebJobs.Host, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
The same error also occurs in our CI build.
Not sure why this error is occurring and how to resolve it. Is it the version of the dotnet CLI (I'm using v1.1)? Is it something else?
UPDATE 2018-01-08
According to a new answer by #theGRS https://stackoverflow.com/a/48156446/621827 this has been resolved.
Previous Answer
Here's what I've found.
dotnet msbuild uses the Microsoft.NET.Sdk.Functions .NETStandard 1.5 library which if you look at the dependencies on NuGet it doesn't use Microsoft.Azure.WebJobs
But if you use the Visual Studio 2017 msbuild it will use the .NETFramework 4.6 version of the library which includes Microsoft.Azure.WebJobs.
My suggestion is to use MSBuild for now.
I was having the same issue as well when running dotnet build, but no longer have this issue after updating Microsoft.NET.Sdk.Functions from 1.0.2 to 1.0.7.
Update to the latest version of this package in your Nuget package manaager and you should be able to run dotnet build again.
I'm trying to build a C# UWP on Jenkins, however I'm getting the following error:
XamlCompiler error WMC1006: Cannot resolve Assembly or Windows Metadata file 'System.Runtime.dll'
Build tools 2015 and VS2015 are both installed on the Jenkins server, and the build script is targeting version 14 of MSbuild
A clean source code tree straight out of version control for a UWP app needs NuGet to run to find dependencies specified in the project.json files.
As a dev, this is something Visual Studio 2015 normally does for you.
On a build server, you will need to run the command-line NuGet 3.x executable so that all the dependencies are pulled down on your build machine before your build runs (MSBuild part).
Go to http://dist.nuget.org/index.html to get hold of the command-line NuGet.exe.
The command will have the form of nuget.exe restore [MyApp.sln].