Skipping restore for project 'SetupWix.wixproj'. The project file may be invalid or missing targets required for restore (NU1503)
Asked Answered
L

2

11

We are using Wixtoolset V3.9 to build our setup. We use the following command to start a build:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" /restore /t:Rebuild /p:Configuration=Release /p:Platform=x64 MySolution.sln /p:BabelEnabled=true

We need the parameter /restore to restore the nuget-packagages on our build-server. Since we build our Wix-Setup by MSBUILD 16 we get the following warning:

Skipping restore for project 'SetupWix.wixproj'. The project file may be invalid or missing targets required for restore.

The warning belongs to category NU1503 (whatever this means). We cannot find a way to solve or even suppress this warning. We have tried to suppress it by adding the code NU1503 to the Project-Properties:

enter image description here

Whatever the reason, the warning still appears.

Question: How can we solve or suppress this warning?

Legalism answered 17/1, 2020 at 9:59 Comment(8)
WiX projects usually don't contain any packages, you should skip them from restoreLeadership
make sense to share your project references and restore commandLeadership
@Pavel Anikhouski: I have added the build-command.Legalism
If you don't have any nuget packages and target in wixproj, you can simply suppress this warning using this line <SuppressSpecificWarnings>1503</SuppressSpecificWarnings>, or in build tab of your proectLeadership
@PavelAnikhouski: We have added the code 1503 into the supression-field of the wix-project, but the warning still appears.Legalism
@Legalism Same. In the OP case and in mine, nuget is running on the build server (Azure in my case)Bedding
Did you ever find a way to suppress this warning?Shipworm
related: github.com/NuGet/Home/issues/13748Yiddish
C
12

TL;DR

You can get rid of NU1503 by including this in your .proj / msbuild file:

  <!-- prevents NU1503 -->
  <Target Name="_IsProjectRestoreSupported"
          Returns="@(_ValidProjectsForRestore)">
    <ItemGroup>
      <_ValidProjectsForRestore Include="$(MSBuildProjectFullPath)" />
    </ItemGroup>
  </Target>
  <Target Name="Restore" />

Source: https://github.com/NuGet/NuGet.Client/blob/537630019c99fdc7bed1b3dfdade72fc3e31692f/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets#L1286-L1298


Detailed explanation

I figured this out by inspecting the msbuild.binlog file via dotnet restore /bl with the awesome MSBuild Binary Log File Viewer tool.

  1. The warning is generated by the WarnForInvalidProjectTask: enter image description here

  2. ... which are generated by the _FilterRestoreGraphProjectInputItems target...

  3. ... which calls a _IsProjectRestoreSupported target, if there is one. enter image description here

Corolla answered 25/1, 2022 at 10:58 Comment(1)
After adding that XML to my project file (.vcxproj) I get build error: C:\code\IVL-Catheter-Programmer\AuthenticatorAccess\AuthenticatorAccess.vcxproj : error MSB4057: The target "_GenerateRestoreGraphProjectEntry" does not exist in the project. ... maybe this solution only works for WIX.Pyx
S
1

The answer by m0sa lead me to a hopefully easier solution. In WarnForInvalidProjectTask there is a check for DisableWarnForInvalidRestoreProjects and you can thereby disable the warning when doing the nuget restore by defining that variable

nuget restore /p:DisableWarnForInvalidRestoreProjects="true"
Select answered 4/5, 2023 at 12:47 Comment(1)
just to add - this also works for passing it as an argument to dotnet restoreBivalve

© 2022 - 2024 — McMap. All rights reserved.