通过代码添加资源时,RESX 文件的 Designer.vb 不会更新

Designer.vb of RESX file does not update when adding resource via code

我正在尝试通过 AddResource(myval.Key, myval.Value) 方法将内容添加到我的 resx 文件中。它工作完美,但唯一困扰我的是那个愚蠢的 Designer 文件。我可以强制它根据它的 resx 文件更新吗?

这就是我将字符串添加到 resx 文件的方式:

For Each entry In list
   Dim resxList As List(Of KeyValuePair(Of String, String)) = New List(Of KeyValuePair(Of String, String))
   Dim reader = New System.Resources.ResXResourceReader(entry.Key)
   Dim node = reader.GetEnumerator()
   While node.MoveNext()
       resxList.Add(New KeyValuePair(Of String, String)(node.Key.ToString(), node.Value.ToString()))
   End While
   reader.Close()
   Using fs As System.IO.FileStream = New System.IO.FileStream(entry.Key, System.IO.FileMode.Open)
      Dim resx As System.Resources.ResXResourceWriter = New System.Resources.ResXResourceWriter(fs)
      Using resx
      If resxList.Count <> 0 Then
         For Each r In resxList
           resx.AddResource(r.Key, r.Value)
         Next
      End If
      For Each myval In entry.Value
        resx.AddResource(myval.Key, myval.Value)
      Next
      resx.Generate()
      resx.Close()
    End Using
    fs.Close()
  End Using
Next

我找到了解决方案:https://github.com/thomaslevesque/AutoRunCustomTool

这是我为我的目的提取的代码:

  Private Function RunCustomToolSuccess(path As String) As Boolean
     Dim targetItem As ProjectItem = _applicationObject.Solution.FindProjectItem(path)

     If targetItem Is Nothing Then Return False

     Dim targetCustomTool As String = CStr(GetPropertyValue(targetItem, "CustomTool"))

     If String.IsNullOrEmpty(targetCustomTool) Then Return False

     Dim vsTargetItem = targetItem.Object
     vsTargetItem.RunCustomTool()
     Return True
  End Function

  Private Shared Function GetPropertyValue(ByVal item As ProjectItem, ByVal index As Object) As Object
     Try
        Dim prop = item.Properties.Item(index)
        If prop IsNot Nothing Then Return prop.Value
     Catch __unusedArgumentException1__ As ArgumentException
     End Try

     Return Nothing
  End Function