如何以编程方式将Genereted Resx文件添加到cproj

时间:2019-06-03 15:11:01

标签: c# resx

我正在尝试将代码生成的resx文件添加到我的项目中。

我目前正在为我的公司制作翻译工具。该工具收集所有需要翻译的项目,并制作一个翻译文件。然后,在翻译时,它将读取新文件并为每个模块创建必要的resx文件。但是,我无法将resx文件正确添加到项目中。

我正在使用ResXResourceWriter生成文件并添加所有必需的资源项。然后,我尝试使用“ Microsoft.Build.Evaluasion.Project.AddItem”将其添加到项目中,但是由于某种原因,文件未正确添加。

一些用于将文件添加到项目中的示例代码

  var p = OpenProject(project.FullName);
  p.AddItem("Resources", newFileLocation);
  p.Save();

创建resx文件的示例代码

using (var newFile = new ResXResourceWriter(newFileLocation))
{
   for (var i = 0; i < baseResxFileXmlNodes.Count; i++)
   {
      var nodeName = baseResxFileXmlNodes[i].Attributes["name"].Value;
      var resxDataNode = new ResXDataNode(nodeName, translationDictionary[nodeName]);
      newFile.AddResource(resxDataNode);
   }
}
UpdateProject(fileInfo, newFileLocation);

0 个答案:

没有答案