Knowledge Base Article Number: Q1571720

Question by: Nasir Ali    Answered by: Adel Helal    Last Updated: 22/06/2007 5:59:37 PM

Spot an error? Please comment about this article

Question:

Why can't I run a VSTO application successfully after install?

My program worked correctly in Visual Studios.NET when i had upgraded my application to use VSTO.

I read an MSDN Article that told me to add a whole bunch of registry keys in my setup package, and then to add a SetSecurity project which had an installer class.

The MSDN article also told me to strongly name my projects otherwise the installer class would not function correctly, however when i tried to strongly name all my projects i realised there was an assembly reference that i couldnt do much about.

I tried a number of ways to disassemble then reassemble the dll (with MSIL's ildasm.exe and ilasm.exe, or copying code from reflector etc.) however that was a dead end.

Is there a way to successfully deploy my VSTO application without the need to strongly name anything?

Answer:

Although the walkthroughs that MSDN have provided only give one example of deploying VSTO products, and the sample projects that they provide give you a strongly named method for deployment, it is not the only way.

After digging into the Installer Class that MSDN provided as a sample (i.e. SetSecurity) i noticed that it only dealt with a couple of command line arguments. More noteably it was running CASPOL.exe to add a .NET security policy to your VSTO application.

caspol.exe -u -q -ag All_Code -url "C:\Program Files\SSW eXtreme Emails\*" Nothing -n  "SSWeXtremeEmails"
caspol.exe -u -q -ag "SSWeXtremeEmails" -strong -file "C:\Program Files\SSW eXtreme Emails\SSWeXtremeEmails.dll" 
        "SSWeXtremeEmails.dll" "14.16.0.0" FullTrust -n "SSWeXtremeEmails"

The problem with this is that it has the "-strong" argument for the specific assembly of your application, and that is where the problem lies.

The fact that you were able to run your application in VS.NET is because VS.NET had automatically added the security policy for you without needing to worry about strong names.

If you go to "Control Panel" > "Administrative Tools" > "Microsoft .NET Framework 2.0 Configuration" you will notice the following security policy:

DotNetFrameworkSecurity
Figure: Security Policy for VSTO Projects when run in VS.NET.

All you will need to do is add something similar for your deployed version.

If you are using Wise Installer, you can add the security policy manually from the .NET Framework configuration as shown below:

AddDotNetFrameworkSecurity
Figure: Add Security Policy for deployed VSTO application.

Make sure that the Membership Condition is set to URL, and the URL itself is a wildcard of the installed directory (i.e. C:\Program Files\SSW eXtreme Emails\*) as shown below:

DotNetSecurityPropertyURL
Figure: Set Membership Condition for installed directory.

On the next dialog set the Permission Set to FullTrust:

DotNetSecurityPropertyPS
Figure: Permission Set for installed directory.

Once that is set up, add that heirarchy in the ".Net Framework Security" section in Wise:

WiseFrameworkSecurity
Figure: Add Security Policy into Wise Installer.

If you are using any other installation package you can place the following command line arguments in a batch file:

REM - Add the VSTO code group. Grant no permission at this level.
caspol.exe -u -q -ag All_Code -allcode FullTrust -n "VSTOProjects"
REM - Add the assembly folders code group. Grant FullTrust permissions to the files within the assembly folder.
caspol.exe -u -q -ag "VSTOProjects" -url "C:\Program Files\SSW eXtreme Emails\*" FullTrust -n "SSW eXtreme Emails"

Keywords: SSW eXtreme Emails!  SSW LookOut! for Outlook    

New Search SSW Custom Support


Note:
Send content changes for KBs to Wilson
Send content changes for Sharepoint.ssw.com.au to Cindy
Send content changes for ASPX pages to Cindy


Benefit from our knowledge and experience!

SSW is the industry leader in Custom Software Development, Software Auditing & Developer Training.

Call us on +61 2 9953 3000 or email us for a free consultation

What does it cost? I’m not in Australia. Can you still help?