This documentation is archived and is not being maintained.

How to: Publish a Project with a Specific Locale 

It is not uncommon for an application to contain components with different locales. In this scenario, you would create a solution with several projects, then publish the projects with different locales. This procedure shows how to use a macro to publish the first project in a solution with the 'en' culture. If you want to try this procedure using a locale other than 'en', make sure you set localeString in the macro to match the locale you're using (for example, 'de' or 'de-DE').


To use this macro, the Publish Location should be a valid URL or UNC share. Also note that IIS needs to be installed on your computer. To install IIS, on the Start menu, click Control Panel. Double-click Add/Remove Programs. In the Add/Remove Programs dialog box, click Add/Remove Windows Components. In the Windows Components Wizard, select the Internet Information Services (IIS) check box from the Components list. Then click Finish to close the wizard.

To create the publishing macro

  1. Open the Macro Explorer. From the Tools menu, click Macros, then Macro Explorer.

  2. Create a new macro module. In the Macro Explorer, select the MyMacros node. From the Tools menu, click Macros, then New Macro Module. Name the module PublishSpecificCulture.

  3. In the Macro Explorer, open the MyMacros node, then open the PublishAllProjects module by double-clicking it (or from the Tools menu, click Macros, then Macros IDE).

  4. In the Macros IDE, add the following code to the module, after the Import statements:

    Module PublishSpecificCulture
        Sub PublishProjectFirstProjectWithEnLocale()
            'NOTE: Projects should be published using the IDE at least once
            ' before using this macro. Items such as the certficate and the security zone
            ' must be set.
            Dim localeString As String = "en"
            'get first project
            Dim proj As Project = DTE.Solution.Projects.Item(1)
            Dim publishProperties As Object = proj.Properties.Item("Publish").Value
            'GenerateManifests and SignManifests must always to true for publishing to work. 
            proj.Properties.Item("GenerateManifests").Value = True
            proj.Properties.Item("SignManifests").Value = True
            'Set publish language.
            'This will set deployment language and pick up all en resource dlls:
            Dim originalTargetCulture As String = publishProperties.Item("TargetCulture").Value
            publishProperties.Item("TargetCulture").Value = localeString
            'Append 'en' to end of publish, install, and update URLs if needed:
            Dim originalPublishUrl As String = publishProperties.Item("PublishUrl").Value
            Dim originalInstallUrl As String = publishProperties.Item("InstallUrl").Value
            Dim originalUpdateUrl As String = publishProperties.Item("UpdateUrl").Value
            publishProperties.Item("PublishUrl").Value = AppendStringToUrl(localeString, New Uri(originalPublishUrl))
            If originalInstallUrl <> String.Empty Then
                publishProperties.Item("InstallUrl").Value = AppendStringToUrl(localeString, New Uri(originalInstallUrl))
            End If
            If originalUpdateUrl <> String.Empty Then
                publishProperties.Item("UpdateUrl").Value = AppendStringToUrl(localeString, New Uri(originalUpdateUrl))
            End If
            Dim slnbld2 As SolutionBuild2 = CType(DTE.Solution.SolutionBuild, SolutionBuild2)
            slnbld2.BuildProject(proj.ConfigurationManager.ActiveConfiguration.ConfigurationName, proj.UniqueName, True)
            'only publish if build was successful.
            If slnbld2.LastBuildInfo <> 0 Then
                MsgBox("Build failed for " & proj.UniqueName)
                slnbld2.PublishProject(proj.ConfigurationManager.ActiveConfiguration.ConfigurationName, proj.UniqueName, True)
                If slnbld2.LastPublishInfo = 0 Then
                    MsgBox("Publish succeeded for " & proj.UniqueName & vbCrLf & "." _
                        & " Publish Language was '" & localeString & "'.")
                    MsgBox("Publish failed for " & proj.UniqueName)
                End If
            End If
            'return urls and target culture to their previous state
            publishProperties.Item("PublishUrl").Value = originalPublishUrl
            publishProperties.Item("InstallUrl").Value = originalInstallUrl
            publishProperties.Item("UpdateUrl").Value = originalUpdateUrl
            publishProperties.Item("TargetCulture").Value = originalTargetCulture
        End Sub
        Private Function AppendStringToUrl(ByVal str As String, ByVal baseUri As Uri) As String
            Dim returnValue As String = baseUri.OriginalString
            If baseUri.IsFile OrElse baseUri.IsUnc Then
                returnValue = IO.Path.Combine(baseUri.OriginalString, str)
                If Not baseUri.ToString.EndsWith("/") Then
                    returnValue = baseUri.OriginalString & "/" & str
                    returnValue = baseUri.OriginalString & str
                End If
            End If
            Return returnValue
        End Function
    End Module
  5. Close the Macros IDE. The focus will return to Visual Studio.

To publish a project with a specific locale

  1. Create a Visual Basic Windows Application project. From the File menu, click New, then Project.

  2. In the New Project dialog box, select Windows Application from the Visual Basic node. Name the project PublishLocales.

  3. Click on Form1 and in the Properties window under the Design node, change the Language property from (Default) to English. Change the form's Text property to MyForm.

    Note that the localized resource DLLs are not created until they are needed, for example, when you change the text of the form or one of its controls after you have specified the new locale.

  4. Publish PublishLocales using the Visual Studio IDE.

    In Solution Explorer, select PublishLocales. From the Project menu, select Properties. In the Project Designer, click the Publish tab. On the Publish page, specify a publishing location of http://localhost/PublishLocales, then click Publish Now.

    When the publish Web page appears, close it. (For this step, you only have to publish the project; you don't have to install it.)

  5. Publish PublishLocales again by invoking the macro in the Visual Studio command window. To view the Command window, from the View menu, click Other Windows, then Command Window, or press CTRL+ALT+A. In the Command Window, type macros; auto-complete will provide a list of available macros. Select the following macro and press Enter:


  6. When the publish process succeeds, it will generate a message saying "Publish succeeded for PublishLocales\PublishLocales.vbproj. Publish language was 'en'." Click OK on the message box. When the publish Web page appears, click Install.

  7. Look in C:\Inetpub\wwwroot\PublishLocales\en. You should see the installed files such as the manifests, setup.exe, and the publish Web page file, as well as the localized resource DLL (by default ClickOnce appends a ".deploy" extension on EXEs and DLLs; you can remove this extension after deployment).

See Also