Search code examples
macosmonovisual-studio-mac

Error MSB4057: The target "Pack" does not exist in the project - Visual Studio for Mac


I have a project at https://github.com/PandaWood/Simple-MAPI.NET

I have always used Build | Create Nuget Package - which always worked - to create a nuget package.

I build it on Visual Studio for Mac (using Mono)

As of today (assuming an update in Visual Studio has caused this) - I get the error above (the target "Pack" does not exist")

I presume this is a bug since I changed no code or configuration since this worked.

Any advice on how to get this working again? The error makes no sense to me in this context

=== Visual Studio Enterprise 2017 for Mac ===

Version 7.3.3 (build 12)
Runtime:
    Mono 5.4.1.7 (2017-06/e66d9abbb27) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 504010007

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.0.0
    1.1.2
    1.0.5
SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks
SDK Versions:
    2.0.0
    1.0.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Mac ===

Version: 4.0.0.216 (Visual Studio Enterprise)

=== Build Information ===

Release ID: 703030012
Git revision: b07492f1e48be596bad92dc4b7a3bc2d128ed0f9
Build date: 2018-01-30 13:15:55-05
Xamarin addins: 7c8f967d67207118dd99a1d0cc9c228045b30c5f
Build lane: monodevelop-lion-d15-5

=== Operating System ===

Mac OS X 10.12.6
Darwin 16.7.0 Darwin Kernel Version 16.7.0
    Thu Jan 11 22:59:40 PST 2018
    root:xnu-3789.73.8~1/RELEASE_X86_64 x86_64

Solution

  • The problem is that the imports for the NuGet.Build.Packaging.props and NuGet.Build.Packaging.targets are incorrect in your project file. The imports currently are pointing to the src/Mapi/packages directory.

    <Import Project="packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.props" Condition="Exists('packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.props')" />
    
    <Import Project="packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.targets" Condition="Exists('packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.targets')" />
    

    Your solution is at the root of the GitHub repository so the packages are being restored there and not in the Mapi folder. So changing the paths as follows should fix the problem with the Pack target not being available:

    <Import Project="..\..\packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.props" Condition="Exists('..\..\packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.props')" />
    
    <Import Project="..\..\packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.targets" Condition="Exists('..\..\packages\NuGet.Build.Packaging.0.1.248\build\NuGet.Build.Packaging.targets')" />