Using Publicize to Create Private Accessors
The command-line tool publicize.exe generates an assembly that contains public types. These public types wrap all the private types in a second assembly. You use publicize to help create unit tests that target private types.
The generated assembly is also known as a private accessor. You can also generate private accessors from the IDE, but you might use publicize.exe instead in Automation, scripting, and build scenarios.
An assembly that you are testing might contain various kinds of private or internal types. When you run publicize.exe and pass the name of that assembly, it generates a private accessor for that assembly. The generated private accessor contains code that enables your test code to access the private types in the assembly. However, it does not provide access to any private or internal delegates or events.
To use publicize.exe, first open a Visual Studio 2008 command prompt. To do this, click Start, click All Programs, point to Microsoft Visual Studio 9.0, point to Visual Studio Tools, and then click Visual Studio 2008 Command Prompt. Use the following syntax with publicize.exe:
Publicize.exe [options] input-assembly
This command wraps all the private types that are present in the input-assembly assembly.
This command has the options /target, /delaysign, and /keyfile. These options are described in the following sections.
Syntax: Publicize.exe /target:[value] input-assembly
The /target option causes the generated assembly to be built to run on a specific platform. The possible values for /target are as follows:
Desktop: Generates a standard CLR private accessor. Desktop is the default value for the target: option.
WebSite: Generates a private accessor that is compatible with a Web site.
Use the WebSite option only for testing code in a Web site that you have created in Visual Studio by selecting Web Site on the File menu.
Device: Generates a private accessor that is compatible with smart devices.
Syntax: Publicize.exe /delaysign input-assembly
Use the /delaysign option to indicate that you do not want to sign the assembly at the current time. Space is reserved in the output assembly so that a digital signature can be added later.
By using /delaysign, you can continue with your testing after you run publicize.exe. A temporary public key token is used, and you can sign the assembly later.
If you use the /delaysign option, you must also use the /keyfile option. The file that you specify with the /keyfile option must contain a public key; optionally, it can also contain a private key.
Syntax: Publicize.exe /keyfile<key file> input-assembly
Use the /keyfile option to sign an assembly when you run publicize.exe. Use the <key file> term to specify the name of an existing file that contains a cryptographic key. The <key file> term can include an absolute or a relative path to the key file.
If you use the /keyfile option, you have the option to also use the /delaysign option. If you use /keyfile without also using /delaysign, the file that you specify with the /keyfile option must contain both a public key and a private key.
/keyfile is also a .NET compiler option. For more information, see Creating and Using Strong-Named Assemblies.
The following command generates a standard desktop private accessor for Myassembly.dll:
The following command generates a private accessor for the Web site MyWebSite:
Publicize.exe /target:WebSite myassemby.dll
The following command generates a standard desktop private accessor for a strong-named assembly, Myassembly.dll, but delays signing until later:
Publicize.exe /delaysign /keyfile<FileWithPublicKey.snk> myassembly.dll
The following command generates a private accessor for use when you test an application that was built to run on a smart device:
Publicize.exe /target:device /keyfile<FileWithKeys.snk> myassembly.dll