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

Update Microsoft.CodeDom.Providers.DotNetCompilerPlatform - closes #59 #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

CZEMacLeod
Copy link
Owner

The default version of Microsoft.CodeDom.Providers.DotNetCompilerPlatform now depends on your target framework version, and will automatically move to 3.11.0 or 4.1.0 if possible, and fallback to the previous value of 3.6.0 otherwise.

Closes #59, although this may need reworked when a better way to handle default versions is included based on #54 and #56.

@leusbj
Copy link
Contributor

leusbj commented Aug 2, 2023

@CZEMacLeod If you are running into problems with this idea.... it might be because that in non-crosstargeted projects, the TargetFrameworkVersion property is calculated/set only at the following import chain
Microsoft.NET.Sdk\Sdk.targets -> Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.BeforeCommon.targets -> Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets

Using these TargetFrameworkVersion values in the "Property Phase" to calculate other Properties when done "After" the Microsoft.NET.Sdk\Sdk.targets is imported. (maybe locate it within the Sdk.targets) could work with something like:

  <!-- When doing greater than/less than comparisons between strings, MSBuild will try to parse the strings as Version objects and compare them as
         such if the parse succeeds. -->  
  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
  <PropertyGroup Condition="'$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)'=='' AND '$(TargetFrameworkIdentifier)' == '.NETFramework'">
    <MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version Condition=" '$(_TargetFrameworkVersionWithoutV)' >= '4.7.2'" >4.1.0</MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version><!-- net 4.7.2+ -->
    <MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version Condition=" '$(_TargetFrameworkVersionWithoutV)' >= '4.6.2' AND '$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)' == '' " >3.11.0</MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version><!-- net 4.6.2, 4.7.2+ -->
    <MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version Condition=" '$(_TargetFrameworkVersionWithoutV)' >= '4.5' AND '$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)' == '' " >3.6.0</MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version><!-- net 4.5 / 4.6 / 4.7.2+ -->
  </PropertyGroup>  

Or potentially use the TargetFrameworkVersion values directly in the "Item Phase" at which time all properties have been calculated/set, potentially like:

  <!-- When doing greater than/less than comparisons between strings, MSBuild will try to parse the strings as Version objects and compare them as
         such if the parse succeeds. -->  
  <ItemGroup Condition="'$(ExcludeSDKDefaultPackages)'=='false' AND '$(ApplySDKDefaultPackageVersions)'=='true'">
    <PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="$(MicrosoftNetCompilersToolset_Version)" Condition="'$(MicrosoftNetCompilersToolset_Version)'!=''"/>
    <PackageReference Update="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)" Condition="'$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)'!=''" />
    <PackageReference Update="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="3.6.0" Condition="'$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)'=='' AND '$(_TargetFrameworkVersionWithoutV)' >= '4.5'" />
    <PackageReference Update="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="3.11.0" Condition="'$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)'=='' AND '$(_TargetFrameworkVersionWithoutV)' >= '4.6.2'" />
    <PackageReference Update="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" Version="4.1.0" Condition="'$(MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version)'=='' AND '$(_TargetFrameworkVersionWithoutV)' >= '4.7.2'" />
  </ItemGroup>

@djdd87
Copy link

djdd87 commented May 15, 2024

Hey @CZEMacLeod, I'm trying to use Microsoft.CodeDom.Providers.DotNetCompilerPlatform 4.1.0 in our .net 4.7.2 project, but unfortunately we can't as it appears to be controlled by MSBuild.SDK.SystemWeb forcing 3.6.0 as a dependency. Is there any chance this can be merged through and deployed out?

@CZEMacLeod
Copy link
Owner Author

CZEMacLeod commented May 15, 2024

@djdd87

Hey @CZEMacLeod, I'm trying to use Microsoft.CodeDom.Providers.DotNetCompilerPlatform 4.1.0 in our .net 4.7.2 project, but unfortunately we can't as it appears to be controlled by MSBuild.SDK.SystemWeb forcing 3.6.0 as a dependency. Is there any chance this can be merged through and deployed out?

For now - if you refer to the documentation you will see that there is a property that allows you to manually select a specific version of the package. This change simply updates the default version.

<PropertyGroup> 
    <MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version>4.1.0</MicrosoftCodeDomProvidersDotNetCompilerPlatform_Version>
</PropertyGroup>

@djdd87
Copy link

djdd87 commented May 15, 2024

Perfect, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants