1
Vote

String Resources package adds build target that fails in command-line build

description

The netfx-System.StringResources NuGet package adds the following target to the project file:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
  <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\netfx-System.StringResources.3.0.2\build\netfx-System.StringResources.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\netfx-System.StringResources.3.0.2\build\netfx-System.StringResources.targets'))" />
</Target>

This target results in an error if you do the following:
  1. Delete the solution package cache ("packages" folder in the solution folder)
  2. Ensure the solution's .nuget\NuGet.targets file has RestorePackages set to true, like this:
    <RestorePackages Condition=" '$(RestorePackages)' == '' ">true</RestorePackages>
  3. Build the solution using a command line similar to this:
    msbuild.exe MySolution.sln /p:platform="xxx" /p:configuration="debug" /p:visualstudioversion="12.0"
Other NuGet packages are downloaded just fine by the build process if the String Resources package is removed, but this package appears to raises an error package restore even starts, complaining that the targets file contained in the package is not present.

comments

bobmeyers wrote Oct 26, 2015 at 4:56 PM

I also get this error if I delete the "packages" folder and then do a clean build inside VS with package restore enabled in the NuGet.targets file.

The only way to get the package added to the solution package cache is to uninstall/reinstall the package manually, or click the "Restore" button at the top of the solution's Manage NuGet Packages dialog, which appears when it detects that some installed packages are missing from the solution. This action presumably does something similar to "nuget.exe restore MySolution.sln -NonInteractive", which works fine from the command line and successfully restores all packages, including the String Resources package. It's only when you try to restore automatically as part of the build process that the EnsureNuGetPackageBuildImports target gets in the way.

bobmeyers wrote Oct 28, 2015 at 11:22 PM

The EnsureNuGetPackageBuildImports target also fails with a non-default packages folder is used (supported since NuGet 2.1), because the target has the packages path hard-coded.