7
votes

I have an ASP.NET Core application that i wish to build on a jenkins machine with MSBuild 15.

When i try to build i get the following error:

C:\Program Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198, 5): error NETSDK1004: Assets file 'C:\sync\Src\Util\myUtil\ob j\project.assets.json' not found. Run a NuGet package restore to generate this file

I understand that i need to do nuget restore somehow, but i failed to make it work.

My build process: Running a batch filed with the following command:

call "%VS150COMNTOOLS%VsDevCmd.bat"
MSBuild DailyBuild.proj /t:DailyBuild /p:VersionNumber=%2 /l:FileLogger,Microsoft.Build.Engine;logfile=Build.log

The DailyBuild.proj file look like this:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <SourcesPath>$(MSBuildProjectDirectory)\..\..\</SourcesPath>
    <CSCleanProperties>BuildType=Clean;Configuration=Release;IsFormalBuild=true</CSCleanProperties>
    <CSBuildProperties>BuildType=ReBuild;Configuration=Release;PauseBuildOnError=false;PublishWebSites=true;VersionName=myProd-$(VersionNumber)</CSBuildProperties>
  </PropertyGroup>

  <Target Name="DailyBuildWithClean">
    <MSBuild Projects="$(MSBuildProjectDirectory)\Make.proj" Targets="Clean" Properties="$(CSCleanProperties)"/>
    <MSBuild Projects="$(MSBuildProjectDirectory)\Make.proj" Properties="$(CSCleanProperties)"/>
    <MSBuild Projects="$(MSBuildProjectDirectory)\Make.proj" Targets="FormalBuild" Properties="$(CSBuildProperties)"/>
  </Target>

  <Target Name="DailyBuild">
    <MSBuild Projects="$(MSBuildProjectDirectory)\Make.proj" Targets="SW;PreparePackFolder" Properties="$(CSBuildProperties)"/>
  </Target>

</Project>

The Make.proj is a proj file containing definitions for many applications to be built, one of them is my ASP.NET Core app.

How do i fix this problem? thank you.

SOLUTION EDIT: Thanks to solution by Martin Ullrich:

Added in the DailyBuild.proj the target Restore, also added in the Make.proj a target called restore as suggested (IE:

<Target Name="Restore">
  <MSBuild Projects="$(SourcesPath)\my.sln" Targets="Restore" />
</Target>

)

3
I have seen this but it doesnt help me. Im trying to build with MSBuild (specifically with a build machine) not with dotnet so dotnet restore is not helping me. Unless you have something more to add because this answer is not helping meTomer Something
If you are going to use .net core you have to follow SDK rules. I would recommend you to get rid off .proj files and msbuild operation and use dotnet CLI and Cake as a build tool.Maxim Goncharuk
I can not find the restore command. Did I miss something?baruchiro
i didnt include the restore command because whichever way i tried it didnt work (msbuild -t:restore or msbuild /t:restore always lead to restore target not found)Tomer Something

3 Answers

11
votes

Add -r (-restore//Restore) to your MSBuild command to trigger a restore before the main build.

The restore parameter will build the Restore target, clear internal caches and then run the rest of the build as specified.

Since you build a custom MSBuild project, you then need to add a Restore target to it:

<Target Name="Restore">
  <MSBuild Projects="$(SourcesPath)\my.sln" Targets="Restore" />
</Target>

(or alternatively add another Restore target on the make.proj file and forward it from there to the solution or individual projects that you need to be restored)

1
votes

Be careful using Restore Nuget packages directly in MS build task configuration. This option is deprecated, as mentioned here for Azure DevOps. (However, I am not sure how context-dependent that is.)

(Important) This option is deprecated. Make sure to clear this checkbox and instead use the NuGet Installer build step.

Source Link: MSBuild

However, I already used that step (in TFS), so this obviously would not fix it for me.

I tried removing the packages-folder in Source Control Explorer as mentioned here, but that did not fix it either.

Inspired by this, I upgraded the TFS NuGet Installer build step to use Nuget 4.0 (in "Advanced" options), and that did fix it. (Maybe in combination with the removal of the packages-folder?)

0
votes

Simply rebuild your project in another location(directory/folder ) and run your solution it works 100%.