Creating VSPackage targeting .net 3.5 and 4 - c#

I have a vspackage that works fine in vs2012, but when I change the target to 4 or 3.5 to target older version, I get compile error :
Error 17 The type or namespace name 'PackageRegistrationAttribute' could not be found (are you missing a using directive or an assembly reference?)
and there is no reference to be added for microsoft.visualstudio.shell.10.0 and 9
Is it possible to create a vspackage in vs2012 for older versions ?
Thanks

Rather than add a reference to the Visual Studio SDK assemblies directly, you can add the appropriate VSSDK.* NuGet packages to your project. For example, the Shell assembly you are looking for to target .NET 3.5 (Visual Studio 2008) is VSSDK.Shell.9.
Note that Visual Studio 2010 includes .NET 4, so it is highly unlikely that you will need to build against .NET 3.5. Visual Studio 2008 and earlier did not support VSIX files to package extensions, so you're really going to have your work cut out if you want to develop an extension supporting those older environments.

Related

Firebird Client - The type or namespace name 'FirebirdSql' could not be found using FirebirdSql.Data.FirebirdClient;

I've been using the Firebird client since 1.5 and I'm now on 2.6 in my
Visual Studio 2010 project with .Net 4.0
In my VS2010 Project I removed the reference FirebirdSql.Data.FirebirdClient.dll v2.6
I've installed the Firebird client 5.12.1.0 and then added the FirebirdSql.Data.FirebirdClient.dll v5.12.1.0 to the solution.
When trying to build the project I now get and error
The type or namespace name 'FirebirdSql' could not be found (are you
missing a using directive or an assembly reference?)
on every
using FirebirdSql.Data.FirebirdClient;
I've restarted the Visual Studio and still get errors.
I can uninstall FirebirdSql.Data.FirebirdClient 5.12.1 and reinstall
FirebirdSql.Data.FirebirdClient 2.6 and (remove old reference and add new reference) the project compiles.
Any ideas why?
The reason why you cannot use the FirebirdClient 5.12.1 most likely is because your .NET-Version of 4.0 is not compatible. When trying to use the newest FirebirdClient you should also get a warning, stating that it was build with .NET-Version 4.5.2 and that you need to change the framework version of your project.
So, either install a newer .NET-Framework (4.5.2 or up) or continue to use the older FirebirdClient version 2.6.
EDIT: I found a better solution on Firebirds website: Use the NuGet-Package, install it by typing Install-Package FirebirdSql.Data.FirebirdClient into the packet-manager console and it will choose the correct package for you.
However, as stated in the comments, you'd need at least NuGet client version 3.6, which doesn't support Visual Studio 2010.

How can I add Excel 2010 (14) PIA to a .NE 3.5 project?

I'm using VS 2012.
The MS Office installed is 2013 x64.
I've downloaded and installed the Office 2010 PIA.
At the VS:
I can only add references to
Microsoft.Office.Core
Microsoft.Office.Interop.Excel
if the project is set to .NET 4.0, not 3.5.
And to do this in the .NET 4.0 project:
((Excel.Worksheet)xlWorkBook.Sheets1).Delete();
I need to add Microsoft.CSharp
In another PC, using VS 2010 and with Excel 2010 x64 installed. I was able to create a project without the Microsoft.CSharp library and the Office PIA is available in .NET 3.5.
So, how can I create a .NET 3.5 project using Excel 2010 (14) PIA in VS 2012 ? What I'm missing here?
I think I repro this problem. This goes wrong when you start with a project that targets .NET 4 and then change the Framework Target to 3.5. The <HintPath> element is missing in the project file, needed by MSBuild version 3 to find the interop assembly.
And the PIA indeed doesn't show up in the assembly list when you target 3.5, it isn't configured to look in the directory where the PIA is stored. So it is simply missing from the list.
Microsoft.CSharp is a very similar story, it is only available as a .NET 4 assembly. It is the support assembly for the dynamic keyword. So when you switch to 3.5, it is going to complain about an assembly whose metadata it cannot read.
Going forward always works better than going backwards in the time. The workaround is simple enough. Just remove Microsoft.CSharp from the referenced assemblies, you will not need it. Or better yet, start your project with 3.5 selected so it never gets added. And to add the Office interop assembly, use Project + Add Reference, click the Browse button. Navigate to the C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\PIA\Office14 directory and select Microsoft.Office.Interop.Excel.dll. The HintPath element is now properly written and MSBuild will be happy.

Do I need visual studio 2012 for .NET 4.5 or is visual studio 2010 fine for 4.5?

I have installed the .NET Framework 4.5 but I can only use .NET Framework 4.0 in my project, which doesn't support BigInteger. Do I need Visual Studio 2012 for 4.5 or is Visual Studio 2010 fine for 4.5?
Yes, you need VS 2012 to use .NET 4.5, however, BigInteger was introduced in .NET 4
Every modern version of Visual Studio (VS 2002 on) is keyed to a specific .NET Framework version, and cannot "see"/use newer versions released after that VS version. More recent VS versions, VS 2008 and beyond can "see" some older framework versions, but CANNOT "see" newer versions of .NET.
VS 2008 keyed to .NET 3.5 and can use 2.0 and 3.0. CANNOT use 4.0 or 4.5
VS 2010 keyed to .NET 4.0 and can use 3.5, 3.0 and 2.0. CANNOT use 4.5
VS 2012 keyed to .NET 4.5 and can use 4.0, 3.5, 3.0 and 2.0
If you need features introduced in .NET Framework 4.5, you need VS 2012.
As others have noted, BigInteger was introduced in .NET 4.0, not .NET 4.5. Through our exchange in the comments, it appears that you had not referenced System.Numerics.dll in your project.
VS project references tell the C# compiler which assemblies define the types that will be used in the C# code being compiled. The default Visual Studio project templates do not include references to the entire .NET framework. Several more specialized assemblies, such as System.Numerics, are omitted; if you want to use them, you have to add the reference yourself.
People frequently confuse the using directive (using System.Numerics;) with the reference itself. The using directive only helps the compiler with resolving type names; it concerns a namespace. For the compiler to find the types themselves, you need a reference, which identifies an assembly.
That information should help clarify the error message "The type or namespace name 'Numerics' does not exist in the namespace 'System' (are you missing an assembly reference?)". This means that the compiler has examined all the referenced assemblies, and it has found no type or namespace called System.Numerics.
To add an assembly reference in VS 2010:
Open the solution explorer
Expand the node for the project in question
Right-click the References node
Choose "Add Reference...". A dialogue box opens.
Open the ".NET" tab
Locate "System.Numerics" in the Component Name list
Click the "OK" button.
Biginteger was introduced in .net 4.0
For version earlier than .net 4.0, try intX
You will need VS2012 for .NET 4.5. VS2010 supports till .NET 4.0 only.
But once you installed .NET 4.5, all .NET 4 applications actually runs on the new version of .NET, the location of system DLLs is C:\Windows\Microsoft.NET\Framework\v4.0.30319
Do you mean VS2010 can only reference system DLLs in C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0?
Won't see new types / new libraries at design time,
but can use reflection to load at runtime?

Can't add system.media.imaging even after adding PresentationCore and WindowsBase

I've just installed C# Visual Express 2010.
The project is created under Console Application.
Any ideas? Thanks.
I'm trying to copy a range in excel and save it as a image file.
I have both PresentationCore and WindowsBase in my References.
But I'm still getting this error.
"Error 1 The type or namespace name 'Imaging' does not exist in the namespace 'System.Media' (are you missing an assembly reference?)"
Target Framwork is .NET Framework 3.5. It's still not working.
On versions of Visual Studio 2010, the default framework used for console applications is .NET Framework 4 Client Profile. The classes you're trying to use are probably not available for this version of the framework.
You need to change your project so it targets the full, .NET Framework 4 (or at least .NET Framework 3.5).
I don't have the express version installed to use as a reference but in regular versions of Visual Studio, you can do this by:
Right clicking on your project in the solution explorer and select Properties.
Under the Application tab, change the Target Framework from .NET Framework 4 Client Profile to .NET Framework 4.
Save.
You'll probably have to reopen your project so the changes could take effect. The assemblies should then be available to you.

C# Windows API Code Pack

I'm using Visual Studio 2010 Express for C# and am having trouble installing the code pack.
I downloaded the source from MSDN and don't know what to do with it?
I opened the WindowsAPICodePack.sln and attempted to build the project and got:
Error 16 The type or namespace name 'ContentPropertyAttribute' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Joe\Downloads\WindowsAPICodePack\Shell\CommonFileDialogs\CommonFileDialogRadioButtonList.cs 13 6 Shell
and
Error 13 The type name 'IComponentConnector' could not be found in the namespace 'System.Windows.Markup'. This type has been forwarded to assembly 'System.Xaml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' Consider adding a reference to that assembly. C:\Users\Joe\Downloads\WindowsAPICodePack\Shell\obj\Debug\Controls\CommandLinkWPF.g.cs 42 99 Shell
each about 5-6 times each.
I attempted to build the samples also but got similar errors.
How do I install the code into Visual Studio?
How do I fix the errors?
How do I include the code into my projects?
Can I make the Library usable in my projects with just a "using" command?
Add a reference to System.Xaml.dll to your project.
I've just downloaded version 1.0.1, opened it up in Visual Studio 2010 Professional and built it with no problems at all.
Check which version of .NET your projects are now targeting. It's possible that the Express edition automatically "upgrades" projects to target .NET 4, whereas mine have been left targeting .NET 3.5.
Another thing to check - do you have .NET 3.5 installed? I'd expect so, but it's worth checking.
When you've built the projects, you need to do two things to use them:
Add a reference to the built assembly (e.g. Microsoft.WindowsAPICodePack.dll)
Add a using directive to the appropriate namespace. (This is actually optional, but otherwise you'll have to use the fully-qualified name for any type in the library, which isn't generally what you want.)

Categories

Resources