microsoft / MSBuildLocator

An API to locate MSBuild assemblies from an installed Visual Studio location. Use this to ensure that calling the MSBuild API will use the same toolset that a build from Visual Studio or msbuild.exe would.
Other
218 stars 83 forks source link

Build 3.0.100-preview6-012264 missing Microsoft.WebApplication.targets #75

Closed carlossanlop closed 1 year ago

carlossanlop commented 5 years ago

From @andez2000 on Monday, July 15, 2019 9:45:37 PM

Missing targets Microsoft.WebApplication.targets error when using MSBuild and Roslyn to iterate through documents in a web project

This was working for the same dotnet core project I wrote that targets either dotnet2.2 or 3.0 when I had 3.0.100-preview5-011568 installed. Having just installed 3.0.100-preview6-012264, the following error is displayed:

Failure - Msbuild failed when processing the file 'G:\andez2000\ld-working\find-endpoints\code-analysis\sample\dotnet\bar-context\Bar.Web\Bar.Web.csproj' with message: The imported project "C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  G:\andez2000\ld-working\find-endpoints\code-analysis\sample\dotnet\bar-context\Bar.Web\Bar.Web.csproj

No code changes were made to my project, nor the solution I am loading. The solution I am loading is a dotnet web application targeting dotnet v4.7.2.

This uses MSBuildLocator.RegisterDefaults() to provide the ground work into locating msbuild, where I have the following information output.

3.0.100-preview5-011568

.NET Core SDK - 3.0.100
        MSBuild:                C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\
        VisualStudioRootPath:   C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\
        Version:                3.0.100

3.0.100-preview6-012264

.NET Core SDK - 3.0.100
        MSBuild:                C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\
        VisualStudioRootPath:   C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\
        Version:                3.0.100

Is it a case of the sdk missing the targets file or something more sinister?

The information listed is from my home PC. My work computer just has the 3.0.100-preview6-012264 installed and not other dotnetcore versions.

In 3.0.100-preview5-011568 the targets file can be found under C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\Microsoft\VisualStudio\v16.0\WebApplications. In 3.0.100-preview6-012264 the folder C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\Microsoft\VisualStudio does not even exist.

When preview 6 is installed alongside preview 5, then the build target issue will appear.

Copied from original issue: dotnet/core#3047

carlossanlop commented 5 years ago

From @carlossanlop on Wednesday, July 31, 2019 6:26:00 PM

@livarcocc @nguerrera is this something your team should look into?

carlossanlop commented 5 years ago

From @livarcocc on Wednesday, July 31, 2019 7:13:17 PM

That target is not support by the .NET Core SDK. It ships with VS and is used for old style web projects.

To use that, you need to use full framework msbuild (msbuild.exe).

carlossanlop commented 5 years ago

From @nguerrera on Wednesday, July 31, 2019 7:27:57 PM

This uses MSBuildLocator.RegisterDefaults()

You would need the locator to pick a Visual Studio installation, and not a .NET Core SDK installation.

This is maybe better discussed at https://github.com/microsoft/msbuildlocator

cc @rainersigwald

rainersigwald commented 5 years ago

@carlossanlop, is your application that uses Locator a .NET Core or desktop .NET application? Right now they find mutually exclusive installations of MSBuild.

carlossanlop commented 5 years ago

@carlossanlop, is your application that uses Locator a .NET Core or desktop .NET application? Right now they find mutually exclusive installations of MSBuild.

@andez2000 this question is for you.

@rainersigwald I'm not the original poster, I merely transferred it from the dotnet/core repo.

andez2000 commented 4 years ago

@carlossanlop, is your application that uses Locator a .NET Core or desktop .NET application? Right now they find mutually exclusive installations of MSBuild.

It is a dotnet core application I was trying to get the dotnet projects built from. It would be great if you could have a single runtime to build both. I guess this is not possible?

rainersigwald commented 4 years ago

@andez2000 MSBuild running on .NET Framework (as in Visual Studio) can build all kinds of projects, and MSBuild running on .NET Core can build only .NET Core SDK projects. So you might be able to meet your goals by changing your application to target .NET 4.8 instead of Core.

Forgind commented 1 year ago

We have better documentation on this now.