actions / runner-images

GitHub Actions runner images
MIT License
9.56k stars 2.95k forks source link

Source generators have been disabled on the current configuration, as they need Roslyn 4.x #5782

Closed roughiain closed 1 year ago

roughiain commented 2 years ago

Description

When Building a Xamarin project on

Users/runner/.nuget/packages/communitytoolkit.mvvm/8.0.0-preview3/buildTransitive/netstandard2.1/CommunityToolkit.Mvvm.targets(41,5): warning : The MVVM Toolkit source generators have been disabled on the current configuration, as they need Roslyn 4.x in order to work. The MVVM Toolkit will work just fine, but features relying on the source generators will not be available. 

Platforms affected

Virtual environments affected

Image version and build link

`vmImage: 'macos-latest'

Is it regression?

no

Expected behavior

Project to successfully build with source generators

Actual behavior

Build fails

Repro steps

  1. Using [ICommand] or [ObservableProperty] source generators project fails to build due to missing roslyn 4.0
mikhailkoliada commented 2 years ago

@roughiain Hi!

Could you provide a minimalistic repo with a sample to reproduce the issue?

roughiain commented 2 years ago

Will do one and attach @mikhailkoliada

roughiain commented 2 years ago

@mikhailkoliada https://github.com/roughiain/PipelineTestSourceGenerators

pipeline output in https://github.com/roughiain/PipelineTestSourceGenerators/blob/b1bafb10c491c1bb6f54900009e20ff1415f2f0d/pipelineoutput.txt

Midnayt commented 2 years ago

Same issue with 8.0.0-preview4 can't buid or run in VS MAC

roughiain commented 2 years ago

@mikhailkoliada Any update

mikhailkoliada commented 2 years ago

Hey @roughiain, we have not had a chance to take a look yet :(

IvanZosimov commented 1 year ago

Hi, @roughiain and @Midnayt 👋 The root cause of the problem is in the version of the Roslyn compiler that is bundled into the Mono project. By now the latest stable version of the Mono is 6.12.0.182 and Roslyn 3.9.0-5.21112.8 is bundled into it. I created this request to update Roslyn's version in the Mono's repo. As a workaround, instead of using XamariniOS@2, you can try to build your application by hand using dotnet build command with the same flags which you specified in XamariniOS task:

- bash: dotnet build /p:Configuration=Release /p:Platform=iPhone /t:Clean "./TestPipeline/TestPipeline.iOS/TestPipeline.iOS.csproj"

Don't forget to change the path to Xamarin iOS targets by changing these lines in TestPipeline.iOS.csproj to:

</ItemGroup>
  <Import Project="/Library/Frameworks/Xamarin.iOS.framework/Versions/15.4.0.0/lib/msbuild/iOS/Xamarin.iOS.CSharp.targets" />
<ItemGroup>
stephenhauck commented 1 year ago

This appears to still be a problem 28 days later Is there an easier way to resolve this? I don't want a custom script .. Appcenter is old enough it should work just fine by now I need this to work for Android and iOS

IvanZosimov commented 1 year ago

Hi, @stephenhauck 👋 Unfortunately, we are still waiting for an answer from the mono team.

stephenhauck commented 1 year ago

Seem like when your commercial product relies on it you should do more than wait ?

InquisitorJax commented 1 year ago

just piping in here - running into the same issue trying to get CI working for Xamarin iOS / Android using github actions

Sample failing github actions here https://github.com/InquisitorJax/Xamarin-Forms-Github-Actions/actions

perhaps there's a way to tell github actions to use a version of msbuild which includes the Roslyn 4.x compilers?

idzikovski commented 1 year ago

Hi, @roughiain and @Midnayt 👋 The root cause of the problem is in the version of the Roslyn compiler that is bundled into the Mono project. By now the latest stable version of the Mono is 6.12.0.182 and Roslyn 3.9.0-5.21112.8 is bundled into it. I created this request to update Roslyn's version in the Mono's repo. As a workaround, instead of using XamariniOS@2, you can try to build your application by hand using dotnet build command with the same flags which you specified in XamariniOS task:

- bash: dotnet build /p:Configuration=Release /p:Platform=iPhone /t:Clean "./TestPipeline/TestPipeline.iOS/TestPipeline.iOS.csproj"

Don't forget to change the path to Xamarin iOS targets by changing these lines in TestPipeline.iOS.csproj to:

</ItemGroup>
  <Import Project="/Library/Frameworks/Xamarin.iOS.framework/Versions/15.4.0.0/lib/msbuild/iOS/Xamarin.iOS.CSharp.targets" />
<ItemGroup>

Hi Ivan. I have tried this workaround, but I get the following error

/usr/local/share/dotnet/sdk/6.0.400/Microsoft.Common.CurrentVersion.targets(1220,5): error MSB3644: The reference assemblies for Xamarin.iOS,Version=v1.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 [/Users/ivandjikovski/Projects/SourceGeneratorsRepro/TestApp.iOS/TestApp.iOS.csproj]

Here is a link to a repro project. I changed the import project as suggested and the build command is this one:

dotnet build TestApp.iOS.csproj -t:restore -t:rebuild -p:Configuration=Release -p:Platform=iPhone

stephenhauck commented 1 year ago

Why are we being presented with workarounds when Roslyn 4 has been out for so long ? If I can build on my desktop with Visual Studio then CI / CD of Appcenter, Git Hub actions or Azure build pipelines should ALL work out of the box ...

IvanZosimov commented 1 year ago

Hi, @InquisitorJax and @idzikovski 👋 To use the MSBuild which has Roslyn 4.x, you need to use dotnet build command instead of msbuild, because msbuild points to MSBuild incorporated into the Mono, which currently still doesn't have Roslyn 4.x. When you specify dotnet build, it points to the MSBuild incorporated into SDK which has Roslyn 4.x. As for question from @idzikovski, try to use this command: dotnet build TestApp.iOS.csproj -t:clean -p:Configuration=Release -p:Platform=iPhone.

stephenhauck commented 1 year ago

Why are we being presented with workarounds when Roslyn 4 has been out for so long ? If I can build on my desktop with Visual Studio then CI / CD of Appcenter, Git Hub actions or Azure build pipelines should ALL work out of the box ...

idzikovski commented 1 year ago

Hi, @InquisitorJax and @idzikovski 👋 To use the MSBuild which has Roslyn 4.x, you need to use dotnet build command instead of msbuild, because msbuild points to MSBuild incorporated into the Mono, which currently still doesn't have Roslyn 4.x. When you specify dotnet build, it points to the MSBuild incorporated into SDK which has Roslyn 4.x. As for question from @idzikovski, try to use this command: dotnet build TestApp.iOS.csproj -t:clean -p:Configuration=Release -p:Platform=iPhone.

Thanks for the reply, this builds successfully, but it doesn't generate a binary. It seems as dotnet build ignores the properties in the csproj file such as <BuildIpa>true</BuildIpa>. Is there a way to configure dotnet to create the ipa file?

IvanZosimov commented 1 year ago

Hi, @InquisitorJax and @idzikovski 👋 To use the MSBuild which has Roslyn 4.x, you need to use dotnet build command instead of msbuild, because msbuild points to MSBuild incorporated into the Mono, which currently still doesn't have Roslyn 4.x. When you specify dotnet build, it points to the MSBuild incorporated into SDK which has Roslyn 4.x. As for question from @idzikovski, try to use this command: dotnet build TestApp.iOS.csproj -t:clean -p:Configuration=Release -p:Platform=iPhone.

Thanks for the reply, this builds successfully, but it doesn't generate a binary. It seems as dotnet build ignores the properties in the csproj file such as <BuildIpa>true</BuildIpa>. Is there a way to configure dotnet to create the ipa file?

@idzikovski , 👋 Yes, there is a way, try to use this command: dotnet build TestApp.iOS.csproj -t:clean -p:Configuration=Release -p:BuildIpa=true -p:Platform=iPhone. More information with other use cases can be found here.

InquisitorJax commented 1 year ago

Hi @IvanZosimov - thanks for the suggestion - unfortunately not having any luck image

Here's the public repo https://github.com/InquisitorJax/Xamarin-Forms-Github-Actions

I'm guessing this entry in the project files is pointing to an incorrect path: image

IvanZosimov commented 1 year ago

Hi @IvanZosimov - thanks for the suggestion - unfortunately not having any luck image

Here's the public repo https://github.com/InquisitorJax/Xamarin-Forms-Github-Actions

Hi, @InquisitorJax 👋 The steps for making it work are pretty the same as in the comment https://github.com/actions/runner-images/issues/5782#issuecomment-1202815693, but for Android the path to Xamarin.Android.CSharp.targets is different.

For iOS:

  1. Use this command: dotnet build XamFormsGithubActions/App1/App1.iOS/App1.iOS.csproj -t:clean -p:Configuration=Release -p:Platform=iPhone
  2. Change/Add this line to your App1.iOS.csproj - <Import Project="/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/msbuild/iOS/Xamarin.iOS.CSharp.targets" />

For Android:

  1. Use this command: dotnet build XamFormsGithubActions/App1/App1.Android/App1.Android.csproj -t:clean -p:Configuration=Release
  2. Change/Add this line to your App1.Android.csproj - <Import Project="/Library/Frameworks/Xamarin.Android.framework/Versions/Current/lib/xamarin.android/xbuild/Xamarin/Android/Xamarin.Android.CSharp.targets" />
stephenhauck commented 1 year ago

Thanks for the workarounds but why .... Microsoft needs to fix this ...

InquisitorJax commented 1 year ago

@IvanZosimov that's good for the github actions build - but those project file changes will then result in the same error when trying to build the project on the local machine - the CSharp.Targes path doesn't exist on a local machine. As @stephenhauck mentions - these work-arounds (hacks) are bound to cause these kinds of issues - would be great if it "just works" . Building on my machine vs cloud image on github / pipelines shouldn't be any different.

... is there not perhaps a way to run a github action to install the CSharp.Targets to the location that the default project file import entry is expecting?

InquisitorJax commented 1 year ago

in the meantime - I implemented a work-around by copying the Release build config to a 'GitHubActions' build config, and then adding conditional inclustions in the project file:

 <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets"  Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'" />
  <Import Project="/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/msbuild/iOS/Xamarin.iOS.CSharp.targets" Condition="'$(Configuration)'=='GitHubActions'"/>
Umer-Mahmood-889 commented 1 year ago

@InquisitorJax Many thanks for a work around which works locally as well with github actions. But the following command: dotnet build -t:clean /p:Configuration=GitHubActions /p:Platform=iPhone /p:BuildIpa=true ./src/app.iOS/app.iOS.csproj only seems to clean the project not build anything. and if I change the command to following: dotnet build -t:build /p:Configuration=GitHubActions /p:Platform=iPhone /p:BuildIpa=true ./src/OBD-S.iOS/OBD-S.iOS.csproj or to dotnet build /p:Configuration=GitHubActions /p:Platform=iPhone /p:BuildIpa=true ./src/OBD-S.iOS/OBD-S.iOS.csproj

I get this error: /Users/runner/.dotnet/sdk/7.0.100/Microsoft.Common.CurrentVersion.targets(1229,5): error MSB3644: The reference assemblies for Xamarin.iOS,Version=v1.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.

Do u have any insights on this?

InquisitorJax commented 1 year ago

@Umer-Mahmood-889 sorry I don't :(

ChristophWeigert commented 1 year ago

Could you find a workaround for your error @Umer-Mahmood-889 ?

Umer-Mahmood-889 commented 1 year ago

@ChristophWeigert Yes, I will get back to you with the solution that worked for me.

Umer-Mahmood-889 commented 1 year ago

@ChristophWeigert following solution worked for me: I added the file named: Directory.Build.props with following contents:

<Project>
  <ItemGroup>
        <!--Specify Compiler for Mac Builds-->
    <PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.4.0">
         <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>
</Project>

Here's the project structure and location of the above mentioned file:

src/
 - Demo-App/
 - Demo-App.Android/
 - Demo-App.iOS/
 - Directory.Build.props
ChristophWeigert commented 1 year ago

@Umer-Mahmood-889 Tried this in Azure DevOps with macOS 12 Image and dotnet build command. But it build fails with.

##[error]/Users/runner/.dotnet/sdk/7.0.102/Microsoft.Common.CurrentVersion.targets(1229,5): Error MSB3644: The reference assemblies for Xamarin.iOS,Version=v1.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
stephenhauck commented 1 year ago

I'm still hopeful but this has me working on switching to Flutter because issues like this not being addressed has my customers asking for Flutter to leave Xamarin and MAUI

This says it will build Xamarin, MAUI and Flutter so I'm looking into it ...

https://codemagic.io/

IvanZosimov commented 1 year ago

Hi, all 👋 Sorry for the late response. I'm closing this issue now as we transferred it directly to the task team. These workarounds may be helpful while the problem isn't solved:

  1. https://github.com/actions/runner-images/issues/5782#issuecomment-1202815693 , https://github.com/actions/runner-images/issues/5782#issuecomment-1249068405
  2. https://github.com/actions/runner-images/issues/5782#issuecomment-1422920694
stephenhauck commented 1 year ago

So it’s being pushed around instead of being worked …. Awesome On Feb 24, 2023, at 10:49 AM, Ivan @.***> wrote: Closed #5782 as completed.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

mathewb629 commented 1 year ago

Stop

On Fri, Feb 24, 2023, 9:07 AM Stephen Hauck @.***> wrote:

So it’s being pushed around instead of being worked …. Awesome On Feb 24, 2023, at 10:49 AM, Ivan @.***> wrote: Closed #5782 as completed.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/actions/runner-images/issues/5782#issuecomment-1444045247, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYQESELHJXC47MGK6X32TYLWZDTF5ANCNFSM5ZLLRYAA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

AdamDiament commented 1 year ago

@ChristophWeigert @Umer-Mahmood-889 I think I have followed all the workaround steps exactly, but I still get the exact same issue

/Users/runner/.dotnet/sdk/7.0.202/Microsoft.Common.CurrentVersion.targets(1229,5): error MSB3644: The reference assemblies for Xamarin.iOS,Version=v1.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 [/Users/runner/work/1/s/SourceCode/ClientApps/VisualService.iOS/VisualService.iOS.csproj]

  1. My azure dev ops pipeline has MacOS12 installed

  2. My build Command is

dotnet build /t:Build /p:Platform=iPhone /p:Configuration=$(BuildConfiguration) /p:Codesignkey="$(APPLE_CERTIFICATE_SIGNING_IDENTITY)" /p:CodesignProvision="$(APPLE_PROV_PROFILE_UUID)" ./Path/To/My.csproj
  1. I changed my targets in CsProj to
 <Import Project="/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/msbuild/iOS/Xamarin.iOS.CSharp.targets" />
  1. I specified compilers in the directory build props (tried both 4.4.0 and the newer 4.5.0)

    Am I missing a step? Did anyone get past this? Perhaps its because the agent is using .net 7 and that doesn't have xamarin ios by default anymore since the move to MAUI - can we get it to include xamarin with a script somehow? I tried using dotnet6, that didn't work.