Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update nuget pacakge adds Error Condition to csproj

I am working on a project with multiple solutions. I recently added a reference to a Nuget package, X in one of my solutions. This caused some version conflicts so i updated the versions of x in all my solutions. Now in solutions which had a conflict, i can see the below lines have been added

<Import Project="..\packages\X.3.3.2.0\build\X.props" Condition="Exists('..\packages\X.3.3.2.0\build\X.props')" />

<Error Condition="!Exists('..\packages\X.3.3.2.0\build\X.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\X.3.3.2.0\build\X.props'))" />

Does anyone know why this gets added and what is the significance of these lines?

like image 239
Rachel Avatar asked May 31 '17 16:05

Rachel


1 Answers

NuGet packages may add build logic to consuming projects by having .props and/or .targets files inside their build folder.

When installed into "classic" csproj files (packages.config method), NuGet adds these statements to the csproj file to include this logic. What this actually is depends on the package. Some set values for use during the build process, some add content files that are copied to the build output and some add custom build steps (transformations etc.).

The <Import … /> element consumes the logic file, with a condition to prevent against the file missing - e.g. when the NuGet packages have not yet been restored (fresh clone/checkout, build server). If the Condition wasn't checking if the file exists, the project file may fail to load in VS.

The <Error … /> element then emits an error message if this file does not exist so that VS will show an error after the project has been loaded.

like image 165
Martin Ullrich Avatar answered Nov 10 '22 00:11

Martin Ullrich