Visual Studio Support (DDEX)

原文 VS2012,VS2013,and VS2015Pro+NpgsqlDdexProvider+EFv6 how to(by @kenjiuno)

Reference: #213

Overview

  1. Install Npgsql DDEX (Data Designer Extensibility) provider.
  2. Install Npgsql ADO.NET Data Provider.
  3. Visual Studio’s Entity Data Model wizard will be enabled for PostgreSQL servers.

Prerequisites

Visual Studio 2015 users:

  1. Visual Studio 2015 Professional or greater editions. Express edition won’t work.
  2. Microsoft Visual Studio 2015 Update 1 is available.

Visual Studio 2013 users:

  1. Visual Studio 2013 Professional Update 2 or greater editions. Express edition won’t work.
  2. Microsoft Visual Studio 2013 Update 5 is available.

Visual Studio 2012 users:

  1. Visual Studio 2012 Professional or greater editions. Express edition won’t work.
  2. Visual Studio 2012 Update 5 is available.

PostgreSQL server installed:

  1. Tested on PostgreSQL 9.3.4 (win-x64)

Install DDEX provider (Npgsql 3.0.x)

  1. Grab Setup_NpgsqlDdexProvider.exe from https://github.com/npgsql/npgsql/releases and run it.
  2. Select all components to install.

Note: The version among NpgsqlEntityFramework6.Npgsql and NpgsqlDdexProvider must be same. For example, if you select Npgsql 3.0.5, it needs EntityFramework6.Npgsql 3.0.5. Also NpgsqlDdexProvider 3.0.5.

Install Npgsql ADO.NET Data Provider to Visual Studio (Npgsql 3.0.x)

  1. Launch Visual Studio.
  2. Open [TOOL] menu, and then click [Setup Npgsql DbProviderFactories…]
  3. Click [OK], 2 times.
  4. Restart Visual Studio.

It asks permission to modify your devenv.exe.config:

This process will add the Npgsql in devenv.exe.config:

  <system.data>
    <DbProviderFactories>
      ...
      <remove invariant="Npgsql" />
      <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=3.0.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
    </DbProviderFactories>
  </system.data>

Setup succeeded.

Note: It will be prompted if administrative privilege is required to modify your devenv.exe.config.

Prepare new project for testing

  1. Launch Visual Studio.
  2. [FILE]→[New]→[Project…]
  3. [Console Application]
  4. Name is [testef] for example.

Install Npgsql for Entity Framework 6 (3.0.x) from NuGet

  1. Right click project [testef]
  2. [Managet NuGet Packages…]
  3. Type “Npgsql” at [Search Online (Ctrl+E)]
  4. Install “Npgsql for Entity Framework 6” (EntityFramework6.Npgsql). Version is 3.0.5 for now.
  5. EntityFramework 6.0.0 and Npgsql are also installed as part of its dependency.

Notice: The assembly versions of Npgsql and NpgsqlDdexProvider must be same. If, for some reason, you need to install a version which isn’t the latest one from NuGet, you need to use the following command in the NuGet Package Manager Console:

Install-Package EntityFramework6.Npgsql -Version <version> where <version> is the version you want to install. A list of versions available can be found in the NuGet Npgsql page: https://www.nuget.org/packages/Npgsql/

Add Npgsql EFv6 provider

Notice: Recent EntityFramework6.Npgsql NuGet package automatically does this process.

  1. Open [App.config], or [Web.config] for web projects.
  2. Add provider-element into providers-element: <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />

An App.config having Npgsql EFv6 privoder:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
    </providers>
  </entityFramework>
</configuration>

Add Npgsql ADO.NET Data Provider

You need to declare the Npgsql ADO.NET Data Provider. Edit one of following config files:

  1. App.config or Web.config
  2. machine.config

If you are using NuGet for your application, we recommend to edit: App.config or Web.config

machine.config are placed in these locations. Framework64 will exist on 64-bit Windows:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config

This is needed part of App.config:

<system.data>
  <DbProviderFactories>
    <remove invariant="Npgsql"/>
    <add name="Npgsql Data Provider"
         invariant="Npgsql"
         description=".Net Data Provider for PostgreSQL"
         type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
         support="FF" />
  </DbProviderFactories>
</system.data>

Note: <remove invariant="Npgsql"/> is important, in case of already having <add invariant="Npgsql" ... /> in machine.config.

Edited App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="Npgsql"/>
      <add name="Npgsql Data Provider"
           invariant="Npgsql"
           description=".Net Data Provider for PostgreSQL"
           type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
           support="FF" />
    </DbProviderFactories>
  </system.data>
</configuration>

Build once

  1. Build your project.

New ADO.NET Entity Data Model

  1. Right click project [testef]
  2. [Add]→[New Item…]
  3. [ADO.NET Entity Data Model]
  4. Default name [Model1] for example.
  5. Click [Add]
  6. [EF Designer from database] at Choose Model Contents.
  7. [New Connection] at Choose Your Data Connection.
  8. [PostgreSQL Database] at Change Data Source.
  9. Fill properties in Connection Properties. It is easy to fill everything by setting [ConnectionString].

My sample ConnectionString:

Host=127.0.0.1;Port=5432;Database=npgsql_tests;Username=npgsql_tests;Password=npgsql_tests

Note: PreloadReader and Compatible properies are obsoleted since Npgsql 3.0.0. Please remove them before submitting ConnectionString.

  1. Select [Yes, include the sensitive data in the connection string.] in this case for easy setup.
  2. Select tables which you want, at Choose Your Database Objects and Settings.

Note: remember the text npgsql_tests_efModel at [Model Namespace].

  1. Click OK for Security Warning. T4 Templates generator warns you as it contains just runnable C# code.
  2. You will get a generated model.

Edit your program.cs

Just my sample code for npgsql_tests_ef database.

About the name of “npgsql_tests_efEntities” class, check your [Model Namespace] entered above. Replace “Model” with “Entities”, like it is “npgsql_tests_efModel”.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace testef
{
    class Program
    {
        static void Main(string[] args)
        {
            using (npgsql_tests_efEntities Context = new npgsql_tests_efEntities())
            {
                foreach (Blogs blog in Context.Blogs)
                {
                    Console.WriteLine(blog.BlogId + " " + blog.Name);
                }
            }
        }
    }
}

Sample output:

How to check if Npgsql DDEX is working correctly. (Npgsql 3.0.x)

(by @kenjiuno)

Reference: #718

NpgsqlDdexProvider 3.0.4 and later has a feature to check Npgsql installation status of your .NET project.

  1. Right click your .NET project
  2. Click [Check Npgsql project installation]

Click a button to start the check!

It will suggest them if you need one or more actions:

[Test and result] shows test cases and their results:

How to check if Npgsql DDEX was correctly loaded. (Npgsql 2.x)

(by @kenjiuno)

Reference: #67

Here are tips to check.

  • Check your connection dialog:
  • Make sure to edit both x86 and x64’s machine.config. VS2013 runs 64bit mode on x64 machine. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
<system.data>
  <DbProviderFactories>
    <add name="Npgsql Data Provider"
         invariant="Npgsql"
         description=".Net Data Provider for PostgreSQL"
         type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.91, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
         support="FF" />
  </DbProviderFactories>
</system.data>

Note that the Version attribute above should match the version of the Npgsql Assembly you are using.

NpgsqlDdexProvider build tips

(by @kenjiuno)

Reference: #213

VS2010 users

You’ll need VS2010 Professional or greater.

SP0 users:

SP1 users:

If you need newer NpgsqlDdexProvider2010.pkgdef, create your own manually. pkgdef is a kind of registry file for our DDEX registration. Note: It is needed only if you change contents of NpgsqlDataProviderRegistration class.

Command example:

H:\Dev\Npgsql\NpgsqlDdexProvider>"H:\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1\VisualStudioIntegration\Tools\Bin\CreatePkgDef.exe" /out=NpgsqlDdexProvider2010.pkgdef /codebase bin\Release-net40\NpgsqlDdexProvider.dll

Output:

	Visual Studio (R) PkgDef Creation Utility.
	Copyright (c) Microsoft Corporation. All rights reserved.

	CreatePkgDef : warning : The Assembly specified at 'bin\Release-net40\NpgsqlDdexProvider.dll' cannot be loaded because an alternate copy with the same identity
	exists in the Assembly probing path at 'H:\Dev\Npgsql\NpgsqlDdexProvider\bin\Release-net40\NpgsqlDdexProvider.dll'. The Assembly at 'H:\Dev\Npgsql\NpgsqlDdexPro
	vider\bin\Release-net40\NpgsqlDdexProvider.dll' will be loaded instead.
	Assembly: NpgsqlDdexProvider 1.0.0.0
	Output file: NpgsqlDdexProvider2010.pkgdef

	インストールされている製品:   NpgsqlDdexProviderPackage、Version 1.0
	パッケージ:          NpgsqlDdexProviderPackage {958b9481-2712-4670-9a62-8fe65e5beea7}
	サービス:          PostgreSQL Provider Object Factory

	SUCCEEDED:        NpgsqlDdexProvider

Check: How to create a pkgdef file for your Visual Studio Packagehttp://blogs.msdn.com/b/dsvst/archive/2010/03/08/how-to-create-a-pkgdef-file-for-your-visual-studio-package.aspx

VS2012 users

You’ll need VS2012 Professional or greater.

VS2013 users

You’ll need VS2013 Professional or greater.

VS2015 users

You’ll need VS2015 Professional or greater.

How to debug Npgsql DDEX extension

In order to debug it, you will need to use the Experimental Instance of Visual Studio.

  • In the NpgsqlDdex project, right click and select properties.
  • Go to Debug tab
  • Click on the radio button for Start External Program. Point it to the devenv.exe binary. On my machine it’s located at

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe

Then set the command line arguments to /rootsuffix Exp

Save everything and now, just right click the NpgsqlDdex project -> Debug -> Run in a new instance. A new Visual Studio instance should be run where the extension will be made available and you can debug it in the first visual studio instance.

Reference: http://stackoverflow.com/questions/9281662/how-to-debug-visual-studio-extensions

时间: 2024-10-31 13:09:13

Visual Studio Support (DDEX)的相关文章

给开心的:Visual Studio .NET Custom Wizards

visual Visual Studio .NET supports a number of built in project types and wizards that generate skeleton projects and solutions depending on the type of application the developer intend to build. These project templates are an excellent way to automa

如何在Visual Studio 2008中安装WCSF June 2007

在本文中, 我将介绍如何在VS2008中使用Web Client Software Factory (WCSF) June 2007. 1.安装 Guidance Automation Extensions Technology Preview (July 2007 Release for Visual Studio 2005 and Visual Studio Beta 2. 2.下载并安装Orca MSI editor (从 Windows SDK 中可以找到).Orca MSI Edito

配置Visual Studio 2008来调试.NET Framework源码的基本步骤

首先,这个功能在Visual Studio 2008 Express版里不支持. 1)安装Visual Studio 2008 QFE.这个QFE只是更新一个Visual Studio调试器的DLL, 以便可以获取源代码,更多细节参加下载页面. 2)运行Visual Studio 2008依次展开Tools->Options->Debugging->General .如果你在Visual Basic Profile环境下运行,你需要将lower left of the Options D

How To Compile Qt 4.7 with Visual Studio 2010

FEBRUARY 1, 2011 Usual way of installing Qt for Visual Studio is to download already compiled binaries from Nokia website. However binaries for the latest Visual Studio 2010 are not available (on the moment of the writing). This post is a step-by-ste

Java开发者的福音:使用 Visual Studio Code 调试 Java 应用程序

对于使用 Visual Studio Code 的 Java 开发者来说,Language Support for Java(TM) by Red Hat 扩展提供了非常好的语言特性支持,比如智能感知和项目支持等.然而,我们也听到一些用户反馈需要调试 Java 程序.今天,我们万分激动地宣布,我们与 Red Hat 合作开发了能让开发者调试 Java 应用程序的轻量级扩展:Java Debugger for Visual Studio Code,它基于 Java Debug Server. 注意

Cocos2d-x Visual Studio Android Project

In the world of game development , Cocos2d is one of the biggest names out there. The open source Cocos2d framework has been the backbone of a vast number of top selling apps and games, provides support for a number of programming languages, and targ

Visual Studio 2013引入联网IDE体验 自动同步设备

近日,Visual Studio 2013以 Visual Studio 2012 和后续的 Visual Studio 更新中的进展为基础构建而成,为开发团队提供需要的解决方案,使其接纳这种转变并开发和交付利用下一波 Windows 平台创新 (Windows 8.1) 的新式应用程序,同时在所有 Microsoft 平台上支持多种设备和服务.设备和服务体验有了根本性的变革,改变了行业对软件开发的处理方式.消费者.客户和员工现在需要一种全新的应用程序.他们要求应用程序在多种屏幕和设备上提供最佳

Visual Studio 2008 可扩展性开发(一):VS概览

前言 Visual Studio是微软最知名的产品之一,在使用微软技术的开发人员的心目中尤为如此.相信这一点无须多说.它建立在IDE(统一开发环境)的基础之上,可用于开发多种不同类型的应用程序. Visual Studio,通常被简称为VS(以下皆按此简称),支持多种平台和编程语言.了解VS的历史以及每个版本的更迭,对学习它的扩展性开发会很有好处.所以在这里简单地说说VS在过去的12年里的历史. VS的历史 在软件领域,VS的历史算比较长的了.在此期间,微软开发了数种编程语言和支持这些语言的可视

Visual Studio 服务器资源管理器连接windows azure 账号连不上为什么呢

问题描述 Visual Studio 服务器资源管理器连接windows azure 账号连不上为什么呢 大家好,Visual Studio 服务器资源管理器连接世纪华联托管的windows azure 账号连不上为什么呢 解决方案 这个你可以打世纪互联的客服电话问问: http://www.windowsazure.cn/support/contact/ 解决方案二: Visual Studio无论是否是中文版,都只能连Azure,而不能连山寨Azure. 解决方案三: 您好,中国版Azure