How can I apply a specific version of .net framework

We have the impression that setting the target structure to the solution properties will limit this application to using only this structure or lower functionality. We just found out that someone can add a link and start using code from a higher-level framework, and the compiler will not complain about a single bit. Since we would like to prevent this in the future, does anyone have any ideas on how I can detect something referencing a higher version or not? I need to skip the build if someone adds code above our goal.

+3
source share
2 answers

Assuming you target .NET 2.0 and higher ... your assembly may fail if you find links to System.Core or other 3.x assemblies (such as WPF) in the "Links to Your Projects" section.

UPDATE

You can start by checking inside each file .PROJfor:

<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>

Then inside the tag <ItemGroup>:

<Reference Include="System.Core">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
  <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>

This can be a custom NAnt task or write your own parser to search for these nodes and build failure.

+1
source

Why do you need to prevent this if it works? As long as you are not using any new features, I believe it is possible to have "advanced" compatible DLL files.

0
source

Source: https://habr.com/ru/post/1716148/


All Articles