Dieser Artikel is nur auf Englisch verfügbar.
Previously, I wrote about using one global msbuild xml file to override nuget package content for local development. While this does work, it comes with a warning if multiple packages use this mechanism:
***Test\packages\***.0.7.1-prerelease-\build\native\***.targets(7,5):
warning MSB4011: "***Test\packagesoverride.xml.user" cannot be imported again. It was already imported at "***Test\packages\***.0.7.1-prerelease-\build\native\***.targets (6,3)".
This is most likely a build authoring error. This subsequent import will be ignored. [***Test\***Test.vcxproj]
While this is not realy a problem, it is a warning. And I don’t like warning. I like my projects to build entirly without warnings.
A soltion for this comes from classic c++ programming: use an include guard. These are the changes required:
The packagesoverride.xml.user must define a default variable. I named it HAS_packagesoverride:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<HAS_packagesoverride>True</HAS_packagesoverride>
<NugetDevPackageTest_testLib_DevDir>C:\Dev\SomeProject\Dir</NugetDevPackageTest_testLib_DevDir>
</PropertyGroup>
</Project>
And now importing this xml in the nuget packages‘ target files can this for this variable to avoid multiple import:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="FaroMorfCopySymbols">
<!-- Import override settings, if they exist -->
<ImportGroup>
<Import
Condition="Exists('$(SolutionDir)packagesoverride.xml.user') and '$(HAS_packagesoverride)' != 'True'"
Project="$(SolutionDir)packagesoverride.xml.user" />
</ImportGroup>
<!-- ... -->