CZEMacLeod / MSBuild.SDK.SystemWeb

This MSBuild SDK is designed to allow for the easy creation and use of SDK (shortform) projects targeting ASP.NET 4.x using System.Web.
MIT License
151 stars 8 forks source link

MSBuild.SDK.SystemWeb/4.0.82 projects do not load in Visual Studio 2022 17.5.0 #52

Closed stevenvolckaert closed 1 year ago

stevenvolckaert commented 1 year ago

I just upgraded my Visual Studio Professional 2022 instance to version 17.5.0, which was released on 21 February 2023.

My MSBuild.SDK.SystemWeb/4.0.82 projects do not load any more:

image

The log file shows:

===================
2023-02-23 09:17:20
LimitedFunctionality
Microsoft.VisualStudio.LanguageServices.ProjectSystem.InvalidProjectDataException: Property 'CommandLineArgsForDesignTimeEvaluation' is required.
   at Microsoft.VisualStudio.LanguageServices.ProjectSystem.EvaluationData.GetRequiredPropertyValue(String name)
   at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.CPS.CPSProjectFactory.<CreateProjectContextAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ProjectSystem.LanguageServices.Workspace.<>c__DisplayClass39_0.<<OnEvaluationUpdateAsync>g__ProcessInitialEvaluationDataAsync|1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.VisualStudio.ProjectSystem.CommonProjectSystemTools.Rethrow(Exception ex)
   at Microsoft.VisualStudio.ProjectSystem.ExceptionFilter.<>c__DisplayClass2_0.<Guard>g__Action|0()
   at GuardMethodClass.GuardMethod(Func`1 , Func`2 , Func`2 )
===================
2023-02-23 09:17:20
LimitedFunctionality
Microsoft.VisualStudio.LanguageServices.ProjectSystem.InvalidProjectDataException: Property 'CommandLineArgsForDesignTimeEvaluation' is required.
   at Microsoft.VisualStudio.LanguageServices.ProjectSystem.EvaluationData.GetRequiredPropertyValue(String name)
   at Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.CPS.CPSProjectFactory.<CreateProjectContextAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ProjectSystem.LanguageServices.Workspace.<>c__DisplayClass39_0.<<OnEvaluationUpdateAsync>g__ProcessInitialEvaluationDataAsync|1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.VisualStudio.ProjectSystem.CommonProjectSystemTools.Rethrow(Exception ex)
   at Microsoft.VisualStudio.ProjectSystem.ExceptionFilter.<>c__DisplayClass2_0.<Guard>g__Action|0()
   at GuardMethodClass.GuardMethod(Func`1 , Func`2 , Func`2 )
===================

I could workaround this by adding property CommandLineArgsForDesignTimeEvaluation to my .csproj files (source):

<PropertyGroup>
  <CommandLineArgsForDesignTimeEvaluation>-langversion:$(LangVersion)</CommandLineArgsForDesignTimeEvaluation>
  <CommandLineArgsForDesignTimeEvaluation Condition="'$(DefineConstants)' != ''">$(CommandLineArgsForDesignTimeEvaluation) -define:$(DefineConstants)</CommandLineArgsForDesignTimeEvaluation>
</PropertyGroup>
jantje85 commented 1 year ago

I have the same problem. The workaround suggested by @stevenvolckaert works

CZEMacLeod commented 1 year ago

Looks like they never fixed 17.5. https://github.com/dotnet/roslyn/pull/66367#issuecomment-1440720451

Either switch your install to 17.4.4 LTSC or use the 17.6.0P1.0 Preview editions...

I haven't had time to evaluate the suggested fix above but that may also work - if those lines are in the common,msbuild includes, I'm not sure why they aren't pulled in already...

stevenvolckaert commented 1 year ago

Thank you for your suggestion @CZEMacLeod!

Adding property CommandLineArgsForDesignTimeEvaluation to the .csproj files works for now, though. When 17.6.0 is available I'll remove it and report back here.

drewnoakes commented 1 year ago

When 17.6.0 is available I'll remove it and report back here.

Hopefully with https://github.com/dotnet/roslyn/pull/67000 this will be fixed in 17.5.1.

leusbj commented 1 year ago

This is just as an FYI, because I don't have an offending version of Visual Studio installed to confirm.

It appears that the CommandLineArgsForDesignTimeEvaluation property is being set in the Microsoft.CSharp.Core.targets file delivered as part of Roslyn. The particular flavor that's actually used during build time is dependent on project config and how build is triggered

This Sdk by default will include a reference to the Microsoft.Net.Compilers.Toolset package (currently 4.3.0). So one more potential work around until projectsystem does not "Require" this property could be:

If you are currently allowing this Sdk to include the default packages (you HAVE NOT overriden the default behavior by setting <ExcludeASPNetCompilers>true</ExcludeASPNetCompilers>), then you could set this Sdk's MicrosoftNetCompilersToolset_Version property to 4.4.0 instead of this Sdk's current default of 4.3.0 with something like:

  <PropertyGroup>
    <MicrosoftNetCompilersToolset_Version>4.4.0</MicrosoftNetCompilersToolset_Version>
  </PropertyGroup>

Alternatively if you are currently not allowing this Sdk to include the default packages (you HAVE overriden the default behavior with <ExcludeASPNetCompilers>true</ExcludeASPNetCompilers>), then you can manually add a PackageReference to one of the later Microsoft.Net.Compilers.Toolset packages with something like:

  <ItemGroup>
    <PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="4.4.0" PrivateAssets="All" />
  </ItemGroup>
ChristophWeigert commented 1 year ago

Seems like they fixed it with 17.5.1

stevenvolckaert commented 1 year ago

I confirm; updating to Visual Studio 17.5.1 fixes this issue.

See Visual Studio 17.5.1 release notes for more information.

CZEMacLeod commented 1 year ago

@leusbj I think the next release of the SDK should bump Microsoft.Net.Compilers.Toolset to 4.4.0 by default to ensure this doesn't break on e.g. build servers etc.

leusbj commented 1 year ago

@leusbj I think the next release of the SDK should bump Microsoft.Net.Compilers.Toolset to 4.4.0 by default to ensure this doesn't break on e.g. build servers etc.

@CZEMacLeod Would like this change to the 'MicrosoftNetCompilersToolset_Version' incorporated with the pending changes to support CPM? Or since the CPM isn't as straight forward, do this change as a standalone change, and back that change into the PR for the CPM Stuff?

CZEMacLeod commented 1 year ago

@leusbj V4.0.88 includes the new version (V4.5.0 in fact). I felt that getting a couple of small changes in to fix some of the outstanding issues was a good bet, then we can do the CPM work as a separate task.