0

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?

2
  • Please, read this. Do you use the deprecated Restore NuGet Packages checkbox in the Visual Studio build step? Commented Sep 12, 2019 at 17:49
  • "Unfortunately", I don't use it. It is like the nuget restore task only restore the nupkg but does not install it... Commented Sep 12, 2019 at 19:11

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Though this would surely work, it misses the point of NuGet which are supposed to deploy the right stuff at the right place automatically. Doing it this way could mean having to do this each time a NuGet is updated or a NuGet is added/removed) and by such is unusable. Since you work on the NuGet team, could you help me understand why VS correctly restore and install/deploy NuGets but not Azure Pipeline Task?
@bkqc, Sorry for the late reply. The difference is because you are trying to stop archiving into code source repository. Since Nuget with a Content folder in the nupkg will add file into the project, which will added to the source control. It is not what you want. So, I give you this workaround. If you want have the same behavior for VS and Azure devops, you have to add the content files to the source control.
thanks for your reply. Unfortunately, it seems to be the only option and as such, I will mark it as being the answer. On the other hand, it dows not make sense that the Nuget content is not used. I get it that files in the repository should have priority over the Nuget but it doesn't prevent Pipeline from doing a complete job. Where could I file a feature request?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.