Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoTargets does not work with multi targeting when project extension is .msbuildproj #155

Open
bash opened this issue Mar 12, 2020 · 5 comments
Labels
Bug Something isn't working Help Wanted Looking for community contributions!

Comments

@bash
Copy link

bash commented Mar 12, 2020

Minimal, Reproducible Example

Source: https://github.com/bash/MSBuildNoTargetsIssueRepro
Failing Travis build: https://travis-ci.com/github/bash/MSBuildNoTargetsIssueRepro/builds/152979950
Error Message:

/usr/share/dotnet/sdk/3.1.102/Microsoft.Common.CurrentVersion.targets(1175,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.0 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 [/home/travis/build/bash/MSBuildNoTargetsIssueRepro/MSBuildNoTargetsIssueRepro.msbuildproj]

Possible Workaround

I believe the issue is that Microsoft.Common.CrossTargeting.targets is never imported when the project extension doesn't correspond to a language.
My workaround sets the propertyLanguageTargets to a custom file, that imports CrossTargeting.targets

@bash bash changed the title Microsoft.Build.NoTargets does not work with multi targeting when project extension ist .msbuildproj NoTargets does not work with multi targeting when project extension ist .msbuildproj Mar 18, 2020
@jeffkl jeffkl added Bug Something isn't working Help Wanted Looking for community contributions! labels Nov 18, 2021
stan-sz added a commit to stan-sz/bicep that referenced this issue Nov 24, 2021
@ViktorHofer
Copy link
Member

Another easier workaround, use the .csproj extension instead. Not perfect but it works...

shenglol pushed a commit to Azure/bicep that referenced this issue Mar 17, 2022
* Bicep nuget packages fixes

Fixes #5253
Fixes #5238
Fixes #5236

* Mitigate lack of multitarget support

microsoft/MSBuildSdks#155

* Revert "Mitigate lack of multitarget support"

This reverts commit 9dcad82.

* Revert "Bicep nuget packages fixes"

This reverts commit be85aff.

* Add support for arrays in (last)indexOf

Closes #4895

* UTs and baseline changes

Upgraded Azure.Deployments.* package dependencies to 1.0.546

* Fix test case

* Update description.
StephenWeatherford pushed a commit to Azure/bicep that referenced this issue Mar 23, 2022
* Bicep nuget packages fixes

Fixes #5253
Fixes #5238
Fixes #5236

* Mitigate lack of multitarget support

microsoft/MSBuildSdks#155

* Revert "Mitigate lack of multitarget support"

This reverts commit 9dcad82.

* Revert "Bicep nuget packages fixes"

This reverts commit be85aff.

* Cleanup all unused using statements
SimonWahlin pushed a commit to SimonWahlin/bicep that referenced this issue Mar 30, 2022
* Bicep nuget packages fixes

Fixes Azure#5253
Fixes Azure#5238
Fixes Azure#5236

* Mitigate lack of multitarget support

microsoft/MSBuildSdks#155

* Revert "Mitigate lack of multitarget support"

This reverts commit 9dcad82.

* Revert "Bicep nuget packages fixes"

This reverts commit be85aff.

* Add support for arrays in (last)indexOf

Closes Azure#4895

* UTs and baseline changes

Upgraded Azure.Deployments.* package dependencies to 1.0.546

* Fix test case

* Update description.
SimonWahlin pushed a commit to SimonWahlin/bicep that referenced this issue Mar 30, 2022
* Bicep nuget packages fixes

Fixes Azure#5253
Fixes Azure#5238
Fixes Azure#5236

* Mitigate lack of multitarget support

microsoft/MSBuildSdks#155

* Revert "Mitigate lack of multitarget support"

This reverts commit 9dcad82.

* Revert "Bicep nuget packages fixes"

This reverts commit be85aff.

* Cleanup all unused using statements
@jzabroski
Copy link

@bash I think you have a typo in the issue. ist -> is

@ViktorHofer I get a build error when using csproj now that I upgraded to VS2022 and uninstalled all old SDKs.

Severity Code Description Project File Line Suppression State
Error MSB3644 The reference assemblies for .NETFramework,Version=v4.0 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 PowerShellBuildProject C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets 1220

My xml is

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.Build.NoTargets/3.3.0" InitialTargets="RunBeforeAnySsrsReport">
  <!-- ReSharper disable UnknownProperty -->
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <OutputPath>bin</OutputPath>
    <RestoreNoCache>True</RestoreNoCache>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="RunBeforeAnySsrsReport.ps1" />
  </ItemGroup>

  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

  <Target Name="RunBeforeAnySsrsReport">
    <PropertyGroup>
      <PowerShellExe Condition=" '$(PowerShellExe)' == '' ">
        "C:\Program Files\PowerShell\7\pwsh.exe"
      </PowerShellExe>
      <ScriptLocation Condition=" '$(ScriptLocation)' == '' ">$(MSBuildProjectDirectory)\RunBeforeAnySsrsReport.ps1</ScriptLocation>
    </PropertyGroup>

    <Message Importance="High" Condition=" '$(PowerShellExe)' == '' " Text=" PowerShellExe not configured. ">
    </Message>
    <Message Importance="High" Condition=" '$(ScriptLocation)' == '' " Text=" ScriptLocation not configured. ">
    </Message>

    <PropertyGroup>
      <PwshCommand>pwsh.exe -NonInteractive -ExecutionPolicy Unrestricted -File &quot;$(ScriptLocation)&quot;</PwshCommand>
    </PropertyGroup>

    <Message Importance="High" Text=" $(PwshCommand) ">
    </Message>

    <Exec Command="$(PwshCommand)" ConsoleToMSBuild="true"  />
  </Target>
</Project>

@bash bash changed the title NoTargets does not work with multi targeting when project extension ist .msbuildproj NoTargets does not work with multi targeting when project extension is .msbuildproj Mar 31, 2022
@bash
Copy link
Author

bash commented Mar 31, 2022

I think you have a typo in the issue. ist -> is

@jzabroski Thanks 🙂

@ViktorHofer
Copy link
Member

@jzabroski do you use the latest version of this msbuildsdk? I think that error was fixed recently.

@kkirkfield
Copy link

Apparently setting the LanguageTargets using your workaround isn't enough. That will get it to build from the command line, but you won't be able to open the project in Visual Studio and will get the error "The project file cannot be opened by the project system because it is missing some critical imports or the referenced SDK cannot be found." If you don't have a solution file, or you added your project to a solution before renaming it to .msbuildproj then you won't get the error because it is using the ProjectTypeGuids of the .csproj file in the solution.

To get this working with the .msbuildproj extension, add this code in addition to your LanguageTargets workaround. This GUID is the same used in the .csproj project type.

<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Then you can add the project to a solution file and it will open and build correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Help Wanted Looking for community contributions!
Projects
None yet
Development

No branches or pull requests

5 participants