“Error MSB4057 missing target pack” when building

2020-03-12 07:16发布

问题:

I'm trying to create a .netstandard nuget package following these instructions, using VS2017 RC. It builds fine, but when I try to create the package using

msbuild /t:pack /p:Configuration=Release

I get an error, that the target pack is not available in my solution:

error MSB4057: The target "pack" does not exist in the project.

I'm not really sure what to do with this message or where I should be looking to fix it. Any suggestions?

回答1:

Thanks to an answer on the MSDN forums I was able to get it working.

You'll have to specify your .csproj in the build command so it won't try to use the solution file (.sln).

msbuild "C:\Users\Administrator\Documents\visual studio 2017\Projects\AppLogger\AppLogger\AppLogger.csproj" /t:pack /p:Configuration=Release

Additionally I had to install the NuGet.Build.Tasks.Pack" package from NuGet.



回答2:

The command msbuild /t:pack /p:Configuration=Release is specifying that MSBuild should run the pack target within the build script. The error indicates that MSBuild isn't able to find that target within the build script (or one of it's imports). Have you double checked your prerequisites? You're either using the wrong build script or it's missing an <import> tag.



回答3:

You must import targets before using them. In project file before using targets write:

  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />