Unable to deploy/push to a GitHub the .Net 4.72 ASMX Webservice because of error MSB4019 (Microsoft.WebApplication.targets" was not found)

Mikhail 41 Reputation points
2023-07-04T18:53:30.67+00:00

I have .NET 4.72 ASMX Web Service that references a .Net Standard 2.0 class library with the Entity Framework

I am using Visual Studio 2022

Everything works fine when I work with the code locally. Everything successfully compiles and runs

However, when I try to push the code to a GIT repository, the code fails. It gives me this error

error MSB4019: The imported project "/usr/share/dotnet/sdk/7.0.305/Microsoft/VisualStudio/v17.0/WebApplications/Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "/usr/share/dotnet/sdk/7.0.305/Microsoft/VisualStudio/v17.0/WebApplications/Microsoft.WebApplication.targets" is correct, and that the file exists on disk.

I tried to remove all those targets references from my proj file, but the VS adds this line automatically

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v17.0\WebApplications\Microsoft.WebApplication.targets" />

If I force this targets reference out of the proj file, I will get a different error

error MSB3644: The reference assemblies for .NETFramework,Version=v4.7.2 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

I also tried to copy target files locally in the project folder and reference them from there

Also, I tried to use

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

Instead of

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v17.0\WebApplications\Microsoft.WebApplication.targets" />

Nothings works

What can I do to successfully push the code to GitHub

Thank you in advance

Developer technologies .NET Other
Developer technologies Visual Studio Other
Developer technologies C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anna Xiu-MSFT 31,056 Reputation points Microsoft External Staff
    2023-07-05T03:47:12.5466667+00:00

    Hi @Mikhail, 

    Welcome to Microsoft Q&A! 

    How did you push the code to a Git repository? 

    For error MSB4019, please try to manually copy the Microsoft.WebApplication.targets file (it may be located at “C:\Program Files\Microsoft Visual Studio\2022<version>\MSBuild\Microsoft\VisualStudio\v17.0\WebApplications”) to the location "/usr/share/dotnet/sdk/7.0.305/Microsoft/VisualStudio/v17.0/WebApplications”. 

    For error MSB3644, please go to your Visual Studio Installer > Modify > Individual components > ensure that “.NET Framework 4.7.2 targeting pack” and “.NET Framework 4.7.2 SDK” are checked. 

    Then, try pushing your code again. 

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.