0
votes

I'm trying to stop archiving into code source repository anything that comes from a Nuget package. For most, since they only have dlls, it works. My problem is that I have one Nuget with a Content folder in the nupkg. When building using VS2017, everything gets installed correctly but when doing the same thing using the build server (Azure DevOps Pipeline), I get

Error MSB3030: Could not copy the file "....." because it was not found.

The pipeline agent version is v.2.122.1 according to Capabilities. NuGet Task logs version 0.2.31 using NuGet 3.3.0.212 with MsBuild 14.0.

I see the nupkg files in the packages folder but the Content folder items don't get copied.

Is there anything special I need to add to my csproj or any additional steps I should add to my build definition?

1
Please, read this. Do you use the deprecated Restore NuGet Packages checkbox in the Visual Studio build step?Jeroen Heier
"Unfortunately", I don't use it. It is like the nuget restore task only restore the nupkg but does not install it...bkqc

1 Answers

0
votes

Is there anything special I need to add to my csproj or any additional steps I should add to my build definition?

You need change your csproj file to link the files from content package instead of add the files into the project. Since you are trying to stop archiving into code source repository anything that comes from a Nuget package, then add a nuget restore task to your build definition.

As test, I create a content package and add a copy event to copy file from the content package:

enter image description here

After installing that package, following content will be add to the project file .csproj and packages.config:

.csproj:

  <ItemGroup>
    <Content Include="resources\Test.txt" />
    <Content Include="resources\Test2.txt" />
  </ItemGroup>

Packages.config:

<packages>
  <package id="TestContentPackage" version="1.0.0" targetFramework="net461" />
</packages>

Then we change the .csproj file to link the files from content package:

  <ItemGroup>
    <Content Include="..\Packages\TestContentPackage.1.0.0\content\resources\Test.txt" />
    <Content Include="..\Packages\TestContentPackage.1.0.0\content\resources\Test2.txt" />
  </ItemGroup>

After change, the files from content package are not added to the project, just link to the project:

enter image description here

To verify the copy command, I add following copy command in the build event:

if not exist $(ProjectDir)TestFolder  mkdir $(ProjectDir)TestFolder
xcopy /y "$(SolutionDir)Packages\TestContentPackage.1.0.0\content\resources\Test2.txt" "$(ProjectDir)TestFolder"

All the things work fine on my local.

Then I build this project with Azure devops, you need add the nuget restore task, otherwise, Visual Studio/MSBuild could not find the files from the packages. And it also work fine.

Note: If you want to copy the files from the content folder, you need copy it from the packages folder.

Hope this helps.