<p>Suppose I have some code that would, in theory, compile against <em>any</em> version of the .net framework. Think "Hello World", if you like. </p>

<p>If I actually compile the code, though, I'll get an executable that runs against one <em>particular</em> version. </p>

<p>Is there any way to arrange things so that the compiled exe will just run against whatever version it finds? I strongly suspect that the answer is no, but I'd be happy to be proven wrong...</p>

<hr>

<p>Edit: Well, I'll go to the foot of our stairs. I had no idea that later frameworks would happily run exe's compiled under earlier versions. Thanks for all the responses!</p>

[{'answer_id': 43943, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 2, 'selected': False, 'text': '<p>Read ScuttGu\'s post about <a href="http://weblogs.asp.net/scottgu/archive/2007/06/20/vs-2008-multi-targeting-support.aspx" rel="nofollow noreferrer">VS 2008 Multi-Targeting Support</a></p>\n\n<blockquote>\n  <p>One of the big changes we are making\n  starting with the VS 2008 release is\n  to support what we call\n  "Multi-Targeting" - which means that\n  Visual Studio will now support\n  targeting multiple versions of the\n  .NET Framework, and developers will be\n  able to start taking advantage of the\n  new features Visual Studio provides\n  without having to always upgrade their\n  existing projects and deployed\n  applications to use a new version of\n  the .NET Framework library.</p>\n  \n  <p>Now when you open an existing project\n  or create a new one with VS 2008, you\n  can pick which version of the .NET\n  Framework to work with - and the IDE\n  will update its compilers and\n  feature-set to match this.  Among\n  other things, this means that\n  features, controls, projects,\n  item-templates, and assembly\n  references that don\'t work with that\n  version of the framework will be\n  hidden, and when you build your\n  application you\'ll be able to take the\n  compiled output and copy it onto a\n  machine that only has an older version\n  of the .NET Framework installed, and\n  you\'ll know that the application will\n  work.</p>\n</blockquote>\n\n<p>That way you can use VS2008 to develop .NET 2.0 projects that will work on both .NET 2.0, 3.0 and 3.5</p>\n'}, {'answer_id': 43946, 'author': 'John Boker', 'author_id': 2847, 'author_profile': 'https://Stackoverflow.com/users/2847', 'pm_score': 4, 'selected': True, 'text': "<p>Im not sure if this is correct, but i'd try to compile it for the lowest version, the higher versions should be able to run the lower versions exe's.</p>\n"}, {'answer_id': 43952, 'author': 'DAC', 'author_id': 1111, 'author_profile': 'https://Stackoverflow.com/users/1111', 'pm_score': 0, 'selected': False, 'text': '<p>Along side multi targeting, the frameworks are backwards compatible, so something compiled to 1.0 will run on 1.1 and 2. Somthing compiled on 1.1 will run on 2 ... etc.</p>\n'}, {'answer_id': 43953, 'author': 'samjudson', 'author_id': 1908, 'author_profile': 'https://Stackoverflow.com/users/1908', 'pm_score': 0, 'selected': False, 'text': '<p>I know <a href="https://stackoverflow.com/questions/43939/targeting-multiple-versions-of-net-framework#43946">@John Boker</a> is correct when it comes to .Net class libraries. You can compile a class library against .Net 1.1 and then use it in a .Net 2.0 or higher project.</p>\n\n<p>I suspect the same is also true for executables.</p>\n'}, {'answer_id': 43954, 'author': 'Ben Scheirman', 'author_id': 3381, 'author_profile': 'https://Stackoverflow.com/users/3381', 'pm_score': 0, 'selected': False, 'text': "<p>with 2005 &amp; 2008, yes (on CLR 2.0)</p>\n\n<p>With 2003, no.. because it compiles down to CLR 1.1</p>\n\n<p>You could theorectically write some code using #if (DOTNET35) and such so that you don't use features outside the compilers knowledge and then run the desired compiler on the app...  I question the usefulness of this though.</p>\n"}, {'answer_id': 43956, 'author': 'Erik van Brakel', 'author_id': 909, 'author_profile': 'https://Stackoverflow.com/users/909', 'pm_score': 0, 'selected': False, 'text': "<p>Well, AFAIK, all .NET versions (except version 1.x) compile to the same bytecode. In case of C#, all new features are simply syntactic sugar, which get transformed into C# 2.0 constructs when compiling.\nThe key point where things could go wrong is when you use C# 3.0 or 3.5 specific DLLs. They don't work well with the .NET 2.0 framework, so you can't use those.</p>\n\n<p>I can't really think of a workaround for this, sorry :(</p>\n"}, {'answer_id': 44055, 'author': 'Morten Christiansen', 'author_id': 4055, 'author_profile': 'https://Stackoverflow.com/users/4055', 'pm_score': 0, 'selected': False, 'text': '<p>On the subject of which .NET framework the user has installed, there is also a new option with the Client Profile that’s available with .NET 3.5 SP1. This basically allows you to ship a small (277k) bootstrap program which downloads and installs the required files (A subset od the full .NET framework).</p>\n\n<p>For more information, and general tips on creating a small .NET installation, see this great <a href="http://www.hanselman.com/blog/SmallestDotNetOnTheSizeOfTheNETFramework.aspx" rel="nofollow noreferrer">blog entry by Scott Hanselman</a>.</p>\n'}]
['https://Stackoverflow.com/questions/43939', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4301/']