Skip to content

Conversation

tanordheim
Copy link
Contributor

@tanordheim tanordheim commented Jan 12, 2024

This is an attempt to add support for .NET 8 to the tool, as it does not run if only .NET 8 SDKs are installed:

You must install or update .NET to run this application.

App: /root/.nuget/packages/dotnet-affected/3.2.0/tools/net7.0/any/dotnet-affected.dll
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '7.0.0' (x64)
.NET location: /usr/share/dotnet/

The following frameworks were found:
8.0.1 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Learn more:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=7.0.0&arch=x64&rid=linux-x64&os=debian.12

As of .NET 8, netcore3.1 is no longer a valid target so support for that has been dropped:

error NETSDK1138: The target framework 'netcoreapp3.1' is out of support and will not receive security updates in the future. Please refer to https://aka.ms/dotnet-core-support for more information about the support policy. [/home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/dotnet-affected.csproj::TargetFramework=netcoreapp3.1]

@tanordheim
Copy link
Contributor Author

@leonardochaia I'm not sure this is all that is needed, tests and such pass locally for me now but I have several .NET SDKs installed so I might have missed something.

@tanordheim
Copy link
Contributor Author

@leonardochaia well that didn't go to well, are you ok with dropping netcoreapp3.1 as a target since that is apparently no longer supported or this an important target to still honor?

@leonardochaia
Copy link
Owner

@leonardochaia well that didn't go to well, are you ok with dropping netcoreapp3.1 as a target since that is apparently no longer supported or this an important target to still honor?

Hi @tanordheim , thanks for the PR! I really really appreciate it!! 🥇

netcoreapp3.1 can definitively be removed, if someone still using it wants to use dotnet-affected they can use an older version.

If you encounter any issues let me know and I may find some time during the weekend to take a look!

Thank you!!
Leo.

@tanordheim
Copy link
Contributor Author

No worries, @leonardochaia, love the project. We just started using it in one of our monorepos and it simplified so many things for us :)

I've pushed a commit now that removes netcore3.1 target support. There is a couple of things I'm unsure of so I'll add PR comments for those so we can discuss with some context.

@tanordheim tanordheim changed the title add .net 8 support add .net 8 support, remove netcore3.1 support Jan 12, 2024
@@ -265,6 +265,7 @@ In most cases it is automatically resolved using the following logic:
- If >= `17.0.0` it will resolve to `net6.0`
- Else if >= `16.11.0` it will resolve to `net5.0`
- Else it will resolve to `netcoreapp3.1`
- TODO
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how true this list is at the moment, I'm not that intimately familiar with how all of this stuff works. How would you suggest I change this?

var projectRootElement = CreateProjectRootElement(projectRootElementFilePath);
// TODO
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running these tests locally I more or less always (but I have also seen it succeed I think) get this error for the net8.0 target. All other targets pass just fine:

Microsoft.Build.Exceptions.InvalidProjectFileException
A numeric comparison was attempted on "$(_TargetFrameworkVersionWithoutV)" that evaluates to "" instead of a number, in condition "'$(PublishRelease)' == '' and '$(_TargetFrameworkVersionWithoutV)' >= '8.0'".  /usr/local/share/dotnet/sdk/8.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1,T2,T3](IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1, T3 arg2)
   at Microsoft.Build.Evaluation.NumericComparisonExpressionNode.BoolEvaluate(IConditionEvaluationState state, LoggingContext loggingContext)
   at Microsoft.Build.Evaluation.OperatorExpressionNode.TryBoolEvaluate(IConditionEvaluationState state, Boolean& result, LoggingContext loggingContext)
   at Microsoft.Build.Evaluation.AndExpressionNode.BoolEvaluate(IConditionEvaluationState state, LoggingContext loggingContext)
   at Microsoft.Build.Evaluation.OperatorExpressionNode.TryBoolEvaluate(IConditionEvaluationState state, Boolean& result, LoggingContext loggingContext)
   at Microsoft.Build.Evaluation.GenericExpressionNode.Evaluate(IConditionEvaluationState state, LoggingContext loggingContext)
   at Microsoft.Build.Evaluation.ConditionEvaluator.EvaluateConditionCollectingConditionedProperties[P,I](String condition, ParserOptions options, Expander`2 expander, ExpanderOptions expanderOptions, Dictionary`2 conditionedPropertiesTable, String evaluationDirectory, ElementLocation elementLocation, ILoggingService loggingServices, BuildEventContext buildEventContext, IFileSystem fileSystem, ProjectRootElementCacheBase projectRootElementCache, LoggingContext loggingContext)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateConditionCollectingConditionedProperties(ProjectElement element, String condition, ExpanderOptions expanderOptions, ParserOptions parserOptions, ProjectRootElementCacheBase projectRootElementCache)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluatePropertyGroupElement(ProjectPropertyGroupElement propertyGroupElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, IDirectoryCacheFactory directoryCacheFactory, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, Boolean interactive)
   at Microsoft.Build.Evaluation.Project.FromProjectRootElement(ProjectRootElement rootElement, ProjectOptions options)
   at DotnetAffected.Core.ProjectFactory.CreateProject(String projectRootElementFilePath) in /Users/trond/Code/dotnet-affected/src/DotnetAffected.Core/ProjectFactory.cs:line 48
   at DotnetAffected.Core.FileSystem.EagerCachingMsBuildGitFileSystem.CreateProjectAndEagerLoadChildren(String path) in /Users/trond/Code/dotnet-affected/src/DotnetAffected.Core/FileSystem/EagerCachingMsBuildGitFileSystem.cs:line 49
   at DotnetAffected.Core.GitChangesProvider.LoadProjectCore(String directory, String pathToFile, String commitRef, Boolean fallbackToHead) in /Users/trond/Code/dotnet-affected/src/DotnetAffected.Core/GitChangesProvider.cs:line 73
   at DotnetAffected.Core.GitChangesProvider.LoadProject(String directory, String pathToFile, String commitRef, Boolean fallbackToHead) in /Users/trond/Code/dotnet-affected/src/DotnetAffected.Core/GitChangesProvider.cs:line 49
   at DotnetAffected.Core.Processor.AffectedProcessor.FindChangedNugetPackages(AffectedProcessorContext context) in /Users/trond/Code/dotnet-affected/src/DotnetAffected.Core/Processor/AffectedProcessor.cs:line 114
   at DotnetAffected.Core.Processor.AffectedProcessor.DiscoverPackageChanges(AffectedProcessorContext context) in /Users/trond/Code/dotnet-affected/src/DotnetAffected.Core/Processor/AffectedProcessor.cs:line 30
   at DotnetAffected.Core.Processor.AffectedProcessorBase.Process(AffectedProcessorContext context) in /Users/trond/Code/dotnet-affected/src/DotnetAffected.Core/Processor/AffectedProcessorBase.cs:line 33
   at DotnetAffected.Core.AffectedExecutor.Execute() in /Users/trond/Code/dotnet-affected/src/DotnetAffected.Core/AffectedExecutor.cs:line 41
   at DotnetAffected.Core.Tests.BaseDotnetAffectedTest.<.ctor>b__1_0() in /Users/trond/Code/dotnet-affected/test/DotnetAffected.Core.Tests/Utils/BaseDotnetAffectedTest.cs:line 16
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at DotnetAffected.Core.Tests.BaseDotnetAffectedTest.get_AffectedSummary() in /Users/trond/Code/dotnet-affected/test/DotnetAffected.Core.Tests/Utils/BaseDotnetAffectedTest.cs:line 24
   at DotnetAffected.Core.Tests.CentralPackageManagementDetectionNestedTests.When_directory_packages_props_changes_without_dependant_projects_nothing_should_be_affected() in /Users/trond/Code/dotnet-affected/test/DotnetAffected.Core.Tests/CentralPackageManagementDetectionNestedTests.cs:line 137
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

I'm not sure why this only fails on net8.0 and not net6.0 and net7.0. What seems to solve it is to add this to the ProjectOptions below:

new ProjectOptions
{
    GlobalProperties = new Dictionary<string, string>{ {"TargetFramework", "net8.0"} },
    // ... existing ProjectOptions
}

The tests for non-net8.0 frameworks still pass with this in place but I'm not sure this is the correct fix. Any thoughts on this?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tanordheim , as you pointed out they were failing due to missing TargetFramework.
I've added it in the sample project generation in tests and that seems to work

@leonardochaia leonardochaia merged commit f815198 into leonardochaia:main Jan 13, 2024
@tanordheim
Copy link
Contributor Author

Great stuff! I thought I'd look at the open issue surrounding deleted files over the weekend as well so if you want to hold off a few days cutting a new release we could maybe get that one included at the same time 🙂

@leonardochaia
Copy link
Owner

Ahh yeah that would be amazing! Thanks bud!
Have a great weekend.
Leo.

@tanordheim tanordheim deleted the dotnet8 branch January 15, 2024 08:57
@tanordheim
Copy link
Contributor Author

Given that the handling of deleted files proved to be a bit more complicated than I thought, as you also commented on that issue, would you be up for releasing a new version with .NET 8 support as we work that out? Would love to test this out!

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

Successfully merging this pull request may close these issues.

2 participants