Making sure C# program can run on machine with only .Net v2 - c#

I'm using VS 2005 Standard SP1, with .Net 3.5 SP1 installed on XP.
The client machines only have .Net 2.0.50727 installed (also on XP).
How can I tell the compiler to reject any classes or methods that are not available in .Net 2?

In Visual Studio 2005 this is not possible because it simply doesn't know about .Net 3.5. Visual Studio 2008 is the first version which understands .Net 3.5.
The best way to make sure you don't use any classes defined in 3.5 is to do the following
Don't reference any DLL's from 3.5 (System.Core,System.Xml.Linq,etc ...)
Run the FxCop rule which spots for 3.5 violations in 2.0 projects. This was initially added to Visual Studio 2008 but I don't see a reason you couldn't use it in a 2005 project if you installed the latest FxCop
Here is a link to a blog article about the FxCop rule I was talking about.
http://blogs.msdn.com/kcwalina/archive/2007/10/02/Multi_2D00_TargetingAndFxCop.aspx
The article does talk about running it against VS2008. But I don't immediately see a reason it couldn't be used in VS2005. But I don't have an install handy to test it on.

Related

Targeted .NET framework for the project depends on Visual Studio version?

I have a funny situation where the C# project targets version of .NET framework depending on Visual Studio version rather than depending on selected .NET target version in Application tab of project's properties.
I had VS2013 premium, update 4, installed and the given project targets .NET 3.5.
Afterwards I've installed VS2015 Enterprise edition and opened solution with the given project with VS2015. Resharper suggested use of nameof() operator (which is .NET 6.0 feature) and this compiled, but when I open given solution in VS2013 it doesn't compile anymore.
Here's the screenshot of Application tab for the given project:
Here's the code snippet from the project when I open it in VS2015:
Which compiles successfully.
And here's the code snippet from the project when I open it in VS20103:
Which doesn't compile.
Any clues about this?
UPDATE:
To rephrase my question. Why does the given project (that targets .NET 3.5) compile at all in VS2015 even though I've used .NET 6.0 feature (nameof() operator)?
This is normal behaviour. If you try to compile something .NET 4.0 specific in VS 2005, you will get the same result. Using a certain VS version you can only develop using up to a certain .NET version.
If I remember correctly:
VS 2005 - .NET 2.0
VS 2008 - .NET 3.5
VS 2010 - .NET 4.0
VS 2013 - .NET 4.5
Update:
The .NET version is indeed not relevant in this case, as the nameof operator is a feature of the Roslyn compiler. Nothing more, nothing less. The VS 2013 definitely uses a different one (at least a compiler which does not cover up with C# 6), therefore it does not compile.

Will Roslyn be part of the .NET framework?

Will Roslyn be part of the .NET framework?
Which version and when?
It is actually available at GitHub but it is fairly big and I'm not able to load it in Visual Studio 2013 on Windows 7 without errors.
No, Roslyn is not included in the .Net Framework. Note that, even in .Net Framework 4.6 you'll still find the legacy csc.exe and vbc.exe compilers which we ship for compatibility reasons. They don't support the latest language features and, at release, you'll see that we've changed their banner text to make it clear that these are not the latest versions.
To get the Roslyn-based C# and VB command-line compilers, you have two options:
Install Visual Studio 2015 RC. or
Install the MSBuild_tools installer package.
You'll find the Roslyn-based command-line compilers at %ProgramFiles(x86)%\MSBuild\14.0\bin
Does Roslyn will be part of the .net framework? Which version and
when?
Roslyn will be officaly shipping with Visual Studio 2015 RTM, which is currently in RC (which you can download and try). It is no longer available for VS2013. Generally, there is also a nice web hosted roslyn compiler called TryRoslyn if you want to try it out.

how to open and compile .net 4.5 winform app in visual studio 2008

I have developed a program in visual studio 2012, my targeting framework was 4.5 and now i want it to be open in vs 2008.
I tried to edit cs file in notepad and edited it, but could not compile.
Is there any workaround?
Any help will be highly appreciated.
Visual Studio 2008 doesn't support the .NET 4.5 Framework. The maximum it supports is 3.5.
Similarly, the maximum VS 2010 supports is .NET 4.0.
You can try changing the target framework to 3.5 before opening it in VS2008, but if you're using anything from the newer frameworks, it won't compile.
Additionally, here's a Wikipedia article with the supported framework (and other information) for each Visual Studio release.
From ScottGu's blog: http://weblogs.asp.net/scottgu/archive/2009/08/27/multi-targeting-support-vs-2010-and-net-4-series.aspx
There isn't any way to target .NET 4 from VS08 and use new features.
Having said that, .NET4 is upwards comaptible with .NET 3.5 - so
applications you build targeting .NET 3.5 with VS08 should work fine
on top of .NET 4.
So in simple words you just can not!
Are you actually using features from the 4.5 framework? There's no IDE-supported way to do this, as other answerers have pointed out. What you can do is this:
Create a new project in Visual Studio 2008.
Add your files to it.
Go through and remove any references to .NET 4.5 and ensure it builds cleanly under .NET 2.0 or whatever VS2008-compatible framework you're targeting.
Rinse and repeat until you get a clean build.
Depending on what you're actually using in code, this may entail a lot of work or very little.

Get VS to highlight all .Net 3.5 SP1 method calls

There are a bunch of new APIs in .Net 3.5 SP1.
Short of uninstalling .Net 3.5 SP1 (or doing dev on a VM), is there a way I can get VS 2008 to target .Net 3.5(RC) as opposed to .Net 3.5 SP1?
Is there a way I can get it to issue a warning when there is an API not supported in 3.5 SP1 which is being invoked?
Similar question: Find code that depends on .NET 3.5 SP1
This actually has a surprisingly tricky answer.
First of all, to get this functionality that is outline in the following post you will need either the latest version of fxcop or VS 2008 SP1.
Once you have that installed there is a new rule (in VS 2008 Team System) called Portability Rules -> Use only API from targeted framework.
But that is not enough
Fxcop is currently shipping with dodgy wpf rules:
Quote from the last line in the above post:
It seems like there are bugs in this
because it didn't complain when I
referenced IEditableCollectionView
which was added in 3.5 SP1. As a
matter of fact, it seems like
"C:\Program Files\Microsoft Visual
Studio 9.0\Team Tools\Static Analysis
Tools\FxCop\Repository\Compatibility\Desktop3.5SP1.xml"
doesn't list ANY of the new WPF
assembly members.
Andrew, thanks for the feedback. You
are correct, there is a bug. The data
for WPF 3.5 SP1 is included, it's just
listed under 3.0 SP2. However, the
'Priority' attribute for this file and
2.0 SP2 is incorrect. I've forwarded this information on to my old team, in
meantime, a workaround is to manually
change these files; for
Desktop3.0SP2.xml change the priority
from '3020' to '3520' and for
Desktop2.0SP2.xml change the priority
from '3015' to '3515'.
So you will need to crack open cmd in admin and fix up those files if you want this to work.
Once that is done, it seems to work fine.

Can I write the code based on .NET Framework 4.0 without vs 2010?

I downloaded and installed the .net framework 4.0, but I didn't install VS 2010, because VS 2010 require the high-performance computer hardware. I have no but I expect to taste the C# 4.0 feature.
you need the .net 4.0 compiler, which at the moment is only available with vs2010.
This thread might answer your question
Where I can download compiler for C# 4.0 without Visual Studio 2010?
The .NET framework client profile includes the compiler (csc.exe). For example, on my machine, it's at:
c:\Windows\Microsoft.NET\Framework64\v4.0.20506\csc.exe
The 32-bit version is at:
c:\Windows\Microsoft.NET\Framework\v4.0.20506\csc.exe
If you're familiar with the command-line compiler syntax, most applications can be written just using it, notepad and referencing the appropriate assemblies. It won't be a terribly pleasant experience though.

Categories

Resources