PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, September 13, 2022

[FIXED] How to compile C# code for multiple frameworks from one set of source files

 September 13, 2022     c#, cross-platform, nuget, visual-studio     No comments   

Issue

I am the author of a number of open source of Nuget packages and I want my Nuget packages to be convenient to use for everyone, but it seems to be unreasonably difficult to configure Visual Studio to produce multiple assemblies targeting different platforms and architectures from one set of source code.

One of the major difficulties is that Microsoft does not do this for it's own Nuget packages, and therefore my project has to reference different versions of Microsoft's packages for each framework I want to target. This in turn means that I need different projects for each platform and this is awkward for projects with a large number of source files.

I can't help feeling that I missed something because many people must be suffering the same issue and it's hard to imagine that after so many years of development of Visual Studio this is still so difficult.

Can anyone recommend a pattern of organizing solutions, projects, source files etc that makes it easy to write code once and have it compile to multiple DLLs that target .Net 4.0, .Net 4.5, .Net Standard 1.0 etc.


Solution

Below is the way to set multiple target frameworks which results into multiple output folders to be produced.

<TargetFrameworks>netstandard1.0;net45;net40</TargetFrameworks>

I don't think there is other way to handle mapping between output platforms and versions of dependencies other than below:

<ItemGroup Condition=" '$(TargetFramework)' == '<version>'">
    <PackageReference Include="<dependency_name>" Version="<version>" />
</ItemGroup>

A detailed description of the migration process from an older project is available here



Answered By - Artyom Ignatovich
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing