Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

71%
+3 −0
Q&A How to make Microsoft.Build.Evaluation.Project use same base properties as Visual Studio?

Microsoft.Build.Evaluation.Project seems to have some rather odd ideas of what values to use when loading projects. In particular, I have a number of projects with the following dependency: <Pa...

1 answer  ·  posted 4y ago by Peter Taylor‭  ·  last activity 4y ago by Peter Taylor‭

#1: Initial revision by user avatar Peter Taylor‭ · 2020-11-12T16:13:50Z (about 4 years ago)
How to make Microsoft.Build.Evaluation.Project use same base properties as Visual Studio?
`Microsoft.Build.Evaluation.Project` seems to have some rather odd ideas of what values to use when loading projects. In particular, I have a number of projects with the following dependency:

    <PackageReference Include="Microsoft.Web.WebJobs.Publish" Version="2.0.0" />

Visual Studio consumes these projects without any problems, but if I try to load one of them with

    var proj = new Project(@"path\to\project.csproj");

it throws an `InvalidProjectFileException` with error message

> The imported project "C:\Program Files\dotnet\sdk\3.1.202\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.202\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk.  E:\Users\ptaylor\\.nuget\packages\microsoft.web.webjobs.publish\2.0.0\build\webjobs.console.targets

The relevant import (which, note, comes from a Microsoft nuget and is not under my control) is

      <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

where `$(VSToolsPath)` is

    $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)

The fundamental problem is that Visual Studio uses the sane value for `$(MSBuildExtensionsPath32)` of `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild`, whereas `Microsoft.Build.Evaluation` is using `C:\Program Files\dotnet\sdk\3.1.202`. I note that the project has `<TargetFramework>net471</TargetFramework>`, so it's not .Net Core and I can't understand why it would make sense to use a .Net Core SDK.

---

The idea behind using `Microsoft.Build.Evaluation.Project` is to write some tooling to complement Visual Studio, so it defeats the point if the two can't agree on basic things like where Microsoft installs its tools. My question is therefore: **is there a clean and robust way to make `Microsoft.Build.Evaluation` use the same properties as Visual Studio?** I can see hacky solutions involving passing values for `MSBuildExtensionsPath32` and similar properties via at least two different mechanisms, but the least hacky value I can think of with the properties available is `$(VSAPPIDDIR)\..\..\MSBuild` and that doesn't really pass the sniff test.