locked
Generate Local Resource automation RRS feed

  • Question

  • User-638027998 posted

    How can we generate the resx file automatically without going to the GENERATE LOCAL RESOURCE ion visual studio

    Is there any utility that can help me automate this process,

    or any sampple code ?

    It looks like microsoft has just embedded this feature in VS, rather than having it as an external utility which i can use.

    I need to automate this process as i can just click a button and it creates the resx files for all files (aspx) on the website

     

    thanks

    Wednesday, June 25, 2008 8:29 AM

All replies

  • User-826062482 posted
    As far as I can tell, resource files are just plain XML files in normal folders. So you can use any tool you want to create those folders and files.
    Thursday, July 3, 2008 5:18 AM
  • User-638027998 posted

    Suppose you have a website of more than 30pages, it becomes a problem to generate for each and every file. While this feature is already in VS, you can

    make a macro and run it through the project to generate the Local_resource.(Need to mention: my colleague helped me in this)

    Thats the nearest we were able to get.

    Hope it helps ...

     

     

     

     

    Monday, July 14, 2008 11:08 AM
  • User2063216690 posted

    <STRIKE>Have you solved this problem? I have a web project with over 600 aspx and ascx sites to localize and it would be great to have such tool that automates the generating of local resources. I have created a little maro but it crasches  after few sites. Here is the code:</STRIKE>

    Here is my macro that automates the localization process:

     

    Option Strict Off
    Option Explicit Off
    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports System.Diagnostics
    Imports System.Collections.Generic
    Imports System.Threading
    Imports System.Windows.Forms
    
    
    
    Public Module RecordingModule
    
    
        Sub TemporaryMacro()
    
            Dim mySolution As Solution = DTE.Solution
            Dim projectFilesList As List(Of String) = New List(Of String)
            Dim currentProject As String = DTE.ActiveDocument.ProjectItem.ContainingProject.FullName
            projectFilesList = ListOfFilesInProject(currentProject, New List(Of String))
    
            Dim solutionName As String = System.IO.Path.GetFileNameWithoutExtension(mySolution.FullName)
            Dim projectName As String = System.IO.Path.GetFileNameWithoutExtension(currentProject)
    
    
            For Each k As String In projectFilesList
                Dim fileName As String = System.IO.Path.GetFileName(k)
                DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
                DTE.ActiveWindow.Object.GetItem(String.Format("{0}\{1}\{2}", solutionName, projectName, PreparePathToFile(k, projectName))).Select(vsUISelectionType.vsUISelectionTypeSelect)
                DTE.ActiveWindow.Object.DoDefaultAction()
                DTE.Windows.Item(fileName).Activate()
                DTE.ExecuteCommand("View.ViewDesigner")
                DTE.Windows.Item(fileName).Activate()
                DTE.ExecuteCommand("Tools.GenerateLocalResource")
                DTE.ExecuteCommand("Window.CloseDocumentWindow")
                DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo)
            Next
        End Sub
    
    
        Function PreparePathToFile(ByVal filePathValue As String, ByVal projectNameValue As String) As String
            Dim filePath As String = filePathValue
            Dim projectName As String = projectNameValue
    
            Dim index As Integer = filePathValue.IndexOf(projectName) + projectName.Length + 1
            Dim returnValue As String = filePath.Remove(0, index)
            Return returnValue
        End Function
    
        Function ListOfFilesInProject(ByVal path As String, ByVal lista As List(Of String)) As List(Of String)
            'Dim projectFilesList As List(Of String) = New List(Of String)
            Dim projectPath As String = path
            If System.IO.Path.GetExtension(projectPath) <> Nothing Then
                Dim index As Integer = projectPath.IndexOf(System.IO.Path.GetFileName(projectPath))
                Dim count As Integer = System.IO.Path.GetFileName(projectPath).Length
                projectPath = projectPath.Remove(index, count)
            End If
    
            Dim folders As String() = System.IO.Directory.GetDirectories(projectPath)
            Dim files As String() = System.IO.Directory.GetFiles(projectPath)
            Dim folder As String
            Dim file As String
    
            For Each file In files
                Dim fileExtension As String = System.IO.Path.GetExtension(file)
                If String.Equals(fileExtension.ToLower, ".aspx") Or String.Equals(fileExtension.ToLower, ".ascx") Or String.Equals(fileExtension.ToLower, ".master") Then
                    lista.Add(file)
                End If
            Next
    
            For Each folder In folders
                ListOfFilesInProject(folder, lista)
            Next
            Return lista
        End Function
    End Module
    
    
    
      
    Monday, August 4, 2008 2:48 AM
  • User1518094527 posted

    Hi


    I am in the same situation as Kaveesh. I tried running this macro that you have given however it throws up an exception on this line


    Dim currentProject As String = DTE.ActiveDocument.ProjectItem.ContainingProject.FullName


    turns out DTE.ActiveDocument is Nothing. Any suggestions on what I might be doing wrong?

    Wednesday, August 26, 2009 10:35 AM
  • User-599278165 posted

    Old post, but replying for anyone else with the same question:


    You have to open one of the code files or document files in the project you want to run this macro on. I am guessing you closed all your windows, and do not have an active window open?

    Friday, June 4, 2010 2:49 PM
  • User-599278165 posted

    Actually, after finding bugs in his macro I reworked it a bit (You still need to open a widow in the web project):

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE90a
    Imports EnvDTE100
    Imports System.Diagnostics
    Imports System.Collections.Generic
    
    Public Module Localization
        Dim _oProject As Project
    
        Sub GenerateLocalResources()
    
            Dim _oProject As Project = DTE.ActiveDocument.ProjectItem.ContainingProject
            GenerateLocalResourcesForProjectItems(_oProject.ProjectItems)
    
        End Sub
    
        Private Sub GenerateLocalResourcesForProjectItems(ByVal oProjectItems As ProjectItems)
            Dim oProjectItem As ProjectItem
            Dim fileName As String
            For Each oProjectItem In oProjectItems
                fileName = oProjectItem.Name.ToLower()
                If (fileName.EndsWith(".aspx") OrElse fileName.EndsWith(".ascx")) Then
                    Dim window As Window = oProjectItem.Open(Constants.vsViewKindCode)
                    window.Activate()
    
                    'oProjectItem.Document.DTE.ExecuteCommand("Edit.FormatDocument")
                    DTE.ExecuteCommand("View.ViewDesigner")
                    DTE.ExecuteCommand("Tools.GenerateLocalResource")
                    DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesYes)
                End If
                If oProjectItem.ProjectItems.Count > 0 Then
                    GenerateLocalResourcesForProjectItems(oProjectItem.ProjectItems)
                End If
            Next
        End Sub
    End Module
    


    Friday, June 4, 2010 4:06 PM
  • User2025643219 posted

    This script may not work in some cases.
    this one waits for window design mode to be completely opened.

    Hope will help.

     

    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE90a
    Imports EnvDTE100
    Imports System.Diagnostics
    
    Imports System.Collections.Generic
    
    Public Module Localization
        Dim _oProject As Project
    
        Sub GenerateLocalResources()
    
            Dim _oProject As Project = DTE.ActiveDocument.ProjectItem.ContainingProject
            GenerateLocalResourcesForProjectItems(_oProject.ProjectItems)
    
        End Sub
    
        Private Sub GenerateLocalResourcesForProjectItems(ByVal oProjectItems As ProjectItems)
            Dim oProjectItem As ProjectItem
            Dim fileName As String
            For Each oProjectItem In oProjectItems
                fileName = oProjectItem.Name.ToLower()
                If (fileName.EndsWith(".aspx") OrElse fileName.EndsWith(".ascx")) Then
                    Dim window As Window = oProjectItem.Open(Constants.vsViewKindDesigner)
                    window.Activate()
    
                    'oProjectItem.Document.DTE.ExecuteCommand("Edit.FormatDocument") 
                    DTE.ExecuteCommand("View.ViewDesigner")
                    DTE.ExecuteCommand("Tools.GenerateLocalResource")
                    DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesYes)
                End If
                If oProjectItem.ProjectItems.Count > 0 Then
                    GenerateLocalResourcesForProjectItems(oProjectItem.ProjectItems)
                End If
            Next
        End Sub
    End Module
    

     

    Tuesday, July 12, 2011 3:36 AM
  • User-1368362018 posted

    For anyone who want to solve this problem:

    I'v made a VisualStudo tool to run Tools.GenerateLocalResource command for each aspx and ascx file in the project.

    It's free, can be downloaded here:http://visualstudiogallery.msdn.microsoft.com/2721069a-104d-4153-b5e0-ab07f0e5ff1f

    Thursday, January 16, 2014 12:14 AM