1
votes

The new dependency validation feature in VS 2017 Enterprise requires an additional component to be checked in the installer. It then upgrades your .csproj files to include Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets. Works like a charm locally but not on a build server:

Error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets" was not found. Also, tried to find "ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" . These search paths are defined in "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe.Config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths.

Our build server is Visual Studio Team Services configured to use latest version of VS (i.e. 2017). What do we need to install/configure to get it working?

2
Are you using the hosted agent or a private agent?Daniel Mann
I believe it's a private agent `cause when we had access to it we had to connect to the corporate VPN.UserControl
I have the same issue but using a hosted Agent. Any suggestion?Exatex

2 Answers

6
votes

Visual Studio Enterprise 2017 is only required to edit the model file. The actual validation will work on non-Enterprise versions of VS2017, VS2015 update 2 or later, and on build machines that don't have Visual Studio installed. You just need the Microsoft.DependencyValidation.Analyzers NuGet packages and the model file.

The Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets file is a legacy of the old (VS2015 and earlier) way of doing dependency validation. If you look in the VS2017 version of the target that ships with VS you'll see that all of the targets are redefined to say Building/Rebuilding/Cleaning a dependency validation project is a no-op. The only reason the targets shipped in VS2017 was to avoid breaking solutions created in VS2015 using the old layer validation mechanism, which did rely on the targets.

If you are not round-tripping between VS2015 and VS2017 then your .csproj files do not need to import those targets. You can either remove the import statement, or if you are round-tripping add a condition so the targets are only imported if then exist e.g.

  <Import Project="$(VSToolsPath)\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets"
    Condition="Exists('$(VSToolsPath)\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets')" />

On the build server, you can just exclude the .modelproj file from the build. Alternatively, you could just tweak the import in the .modelproj so that it works in both VS2017 and VS2015, but won't fail if the targets don't exist:

  <Import Project="$(VSToolsPath)\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets"
    Condition="Exists('$(VSToolsPath)\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets')" />

  <!-- In the .modelproj file, we need to define a Build target if we're not importing the modeling targets -->
  <Target Name="Build" Condition="!Exists('$(VSToolsPath)\ArchitectureTools\Microsoft.VisualStudio.TeamArchitect.ModelingProject.targets')"/>
0
votes

You need to install Visual Studio Enterprise on the build agent and make sure to also install the Architecture tools. Same as you would on a developer workstation.

(this is not correct -- see other answer)