In this post I am going to explain how to use External DLL in SharePoint2010 Webpart
Approach 1
With your SP 2010 project open in VS 2010, double click on package.package from solution explorer.
You will see the package designer window getting opened. At the bottom of this screen you will see three editor switches. we have to switch to “Advanced” mode to add additional dlls.
Click on that gray looking
button that says “Advanced”
Then the Advanced mode will come up with 3 buttons, looks like the below snapshot
Initially the screen will be empty as there are no additional dlls defined. Let’s add some.
Click Add, and you will be prompted to selected external dll or dll from one of the opened Project
output. For external dll select “Add existing Assembly”.
Then it will bring you to "Add Existing Assembly wizard"
Where you need to enter the information about the external dll, deployment target(GAC / WebApplication) and Safe Control entry for web.config. If require you can add resources.
Click ok and that’s it. Just repackage your WSP by right clicking on the project and click package, and you will see that the resulting wsp will contain these external dlls automatically.
Verification:
Once finish these things, we can verify whether we have done these correctly by checking Safe Control entry in web.config file and pkg folder.
In the solution package (debug/Release based on the solution configuration) you can see the external dll
In web.config you get an entry which you have entered in "Add Existing Assembly wizard"
Note: In this approach you should have strong key name for the external dll.
Approach 2:
There is another very good approach which is mentioned below in steps. That is to deploy the dll directly to the site bin folder. Here are the steps to accomplish:
3. Add a safe control entry to the web config file. Do not mention public key token. Do not strong name the project.
4. That's it, your code is deployed in the site's bin directory and its information is located in the config file. Go Ahead and populate the web part gallery with the web part and add it to a page.
Advantages:
1. Biggest advantage is the fact that you do not have to reset iis after every compilation of code.
2. You can directly copy the dll from the other bin folders to this as and when required.
DisAdvantage
1. As you are deploying code to the bin folder of particular site, it will not be available globally. That means you will need to add the dll to every site's bin folder.
Approach 1
With your SP 2010 project open in VS 2010, double click on package.package from solution explorer.
You will see the package designer window getting opened. At the bottom of this screen you will see three editor switches. we have to switch to “Advanced” mode to add additional dlls.
Then the Advanced mode will come up with 3 buttons, looks like the below snapshot
Initially the screen will be empty as there are no additional dlls defined. Let’s add some.
Click Add, and you will be prompted to selected external dll or dll from one of the opened Project
output. For external dll select “Add existing Assembly”.
Then it will bring you to "Add Existing Assembly wizard"
Where you need to enter the information about the external dll, deployment target(GAC / WebApplication) and Safe Control entry for web.config. If require you can add resources.
Click ok and that’s it. Just repackage your WSP by right clicking on the project and click package, and you will see that the resulting wsp will contain these external dlls automatically.
Verification:
Once finish these things, we can verify whether we have done these correctly by checking Safe Control entry in web.config file and pkg folder.
In the solution package (debug/Release based on the solution configuration) you can see the external dll
In web.config you get an entry which you have entered in "Add Existing Assembly wizard"
Note: In this approach you should have strong key name for the external dll.
Approach 2:
There is another very good approach which is mentioned below in steps. That is to deploy the dll directly to the site bin folder. Here are the steps to accomplish:
1. Set Output path of the projects (Project in which you are keeping
webpart control classes) to the site bin folder. You can find the path by
navigating to C:\Inetpub\wwwroot\virtual directory\port number\bin
2. Build the solution and make sure it is compiling successfully.
3. Add a safe control entry to the web config file. Do not mention public key token. Do not strong name the project.
4. That's it, your code is deployed in the site's bin directory and its information is located in the config file. Go Ahead and populate the web part gallery with the web part and add it to a page.
Advantages:
1. Biggest advantage is the fact that you do not have to reset iis after every compilation of code.
2. You can directly copy the dll from the other bin folders to this as and when required.
DisAdvantage
1. As you are deploying code to the bin folder of particular site, it will not be available globally. That means you will need to add the dll to every site's bin folder.
No comments:
Post a Comment