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
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.
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/"
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 need to install Nuget Package ProductionStackTrace, so I use the following command
PM> Install-Package ProductionStackTrace
But when I execute this command I get the following error
The source at Microsoft Visual Studio Offline Packages [C:\Program Files (x86)\Microsoft SDKs\NuGetPackages] is unreachable.
I checked the path and yes the package is not there; isn't Nuget Package added by default? If not, from where I can add it?
Visual Studio provides some common packages for us to use in the Microsoft SDKs\NuGetPackages folder when our computer doesn't have network.
The C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\ folder is not means that the cache for the packages has been installed before from internet. So the package ProductionStackTrace will not add into this folder.
If you want to use this package without network, you need to download it when you have network. You can download it from the nuget.org.
Certainly, you can also add this package in to the Microsoft SDKs\NuGetPackages so that you can use it when you do not have a network. The add command line is:
nuget add <packagePath> -source <sourcePath> [options]
You can refer to the nuget Add reference for detail.
Hope this can help you.
Unclear why this happened for my installation, but Visual Studio (VS 2022 preview at this time) had an offline location (good), but no package source to nuget.
This caused my build to fail on packages not found in the offline directory.
Hence I ended up adding a Package source in Visual Studio for Nuget as:
nuget.org
https://api.nuget.org/v3/index.json
Which then allowed VS to do a Restore of packages to succeed. Then not having to do a nuget install Newtonsoft.json -source ... type command for each failed package.
for Visual Studio Mac, packages are copied into the path /Users/{username}/.nuget/packages
You can choose menu for Visual Studio->Preferences->Nuget->Sources and add a new source using this path and install already cached packages.
manually dowload from nuget.org package with extension NUPKG file,and copy paste that into (C:\Program Files (x86)\Microsoft SDKs\NuGetPackages) relative path
OR
RUN CMD COMMAND:
dotnet add projectpath package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore --version 6.0.0
At trying to run a test application i obtain the following error twice:
There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll", "x86".
This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project. TestMobile.Core
mismatch MSIL x86
I have .NET Framework installed, as well as windows 8 SDK tools and using MultilingualAppToolKit.
I already have verified the configuration manager and everything seems to be fine. Platform target, targeting "Any CPU"
Copying over my existing version of .NET Portable Library Reference Assemblies fixed the issue for me.
I encountered this problem after installing a patch to Visual Studio 2015 Update 3, read vvolkgang's response and initially discounted it because I already had folders within C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable, and the dates of those folders were later than those contained within the reference assemblies archive I had downloaded. What I should have done was to check the right part of the folder hierarchy. Take a look at your project file; in my case I had these settings:
<TargetFrameworkProfile>Profile49</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
If those are your settings, you need to check the contents of C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile49. If you're using a different profile or targeting a different version of the framework, adjust the path accordingly. When I checked that folder, I discovered that I had lots of XML files but no DLLs; copying the files from Microsoft .NET Portable Library Reference Assemblies 4.6 and choosing not to replace any files that already existed fixed my build issues.
Had this problem after installing Visual Studio 2015 Update 2. Try this, the first one solved my problem:
Install Portable Class Libraries v4.6
Download Install the Portable Class Libraries v4.6. If you install this it puts a .zip file into the directory:
"C:\Program Files (x86)\Microsoft .NET Portable Library Reference Assemblies 4.6"
Unpack and copy the contents into "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\"
Install the PCL Tools
Download Portable Class Library Tools
Install by running PortableLibraryTools.exe /buildmachine
Source: Matt Ward # https://forums.xamarin.com/discussion/comment/80535/#Comment_80535
I finnally was able to build my project without this filthy error. It seems that i needed to install PortableLibraryTools from VS2010. It worked after that.
Reference: http://forums.xamarin.com/discussion/25538/xamarin-xaml-example-problem-using-pcl
If you are on a build Server and getting this Error/Warning , just install MSBuild 17 with its optional installations which contains all the SDKs and Portable libraries.