[英]Best way to manage resources(Not necessarily RESX files) in .Net solution
This sounded like a trivial question initially but I did not come across any solid/best practice solution on how to do this so I am asking the question here. 最初,这听起来像是一个琐碎的问题,但是我没有找到关于如何执行此操作的任何可靠/最佳实践解决方案,因此我在这里提出问题。 Now, let's imagine that we have to work with couple of ".txt" files in our code which is in a class library. 现在,让我们想象一下,我们必须在类库中的代码中使用几个“ .txt”文件。
Now, I think there are 3 major ways to handle this: 现在,我认为有3种主要方法可以解决此问题:
Just put everything in your Bin/Debug/Resources folder of the calling application and in your code use "Resources\\*.txt". 只需将所有内容放入调用应用程序的Bin / Debug / Resources文件夹中,并在代码中使用“ Resources \\ *。txt”即可。 I think this is the simplest and most unobtrusive way to handle this. 我认为这是处理此问题的最简单,最简单的方法。 However, there are many trivial problems with it: 但是,它有许多琐碎的问题:
When you check in the source control would not check-in the files inside the Bin/Debug folder 当您签入源代码管理时,不会签入Bin / Debug文件夹中的文件
So in this case, probably adding the folder one level above and then writting post-build scripts is the most efficient option I guess? 因此,在这种情况下,我猜最可能是最有效的选择吗?可能是在上一级文件夹中添加文件夹,然后编写构建后脚本。
Add resources folder on the same level as Bin folder . 将资源文件夹添加到与Bin文件夹相同的级别 。 That way we can successfully manage it using the source control. 这样,我们可以使用源代码管理成功地对其进行管理。 however now when we need to reference it through our code it becomes tricky 但是现在当我们需要通过我们的代码引用它时,它变得很棘手
We can reference this files assuming that the Binary folder's structure is like Bin/Debug and reference to the Resources folder like ..\\..\\Resources 我们可以在Binary文件夹的结构类似于Bin / Debug的情况下引用此文件,并在.. \\ .. \\ Resources的Resources文件夹下进行引用
But this structure is not always guaranteed what if the binary folder structure is like Bin/ (without any debug folder in it) then ../../Resources is going to fail 但是 ,如果二进制文件夹结构类似于Bin /(其中没有任何调试文件夹),那么../../Resources将会失败, 但这种结构并不能始终保证
Add all the txt files as .RESX files. 将所有txt文件添加为.RESX文件。 But I am not sure if it is the practice around everywhere and the most popular way to store resources. 但是我不确定这是否是到处都是的实践,也是最流行的存储资源方式。
-Also, the code that we have to write to access the resources files sounds like cumbersome as oppose to just picking up the file from windows file system. -此外,我们要编写的访问资源文件的代码听起来很麻烦,因为反对只从Windows文件系统中提取文件。
Probably I am missing something trivial but I was just curious and was thinking that it should be much more simpler than this. 可能我缺少一些琐碎的东西,但我只是好奇,并认为它应该比这简单得多。 Any suggestions? 有什么建议么?
Create a different project in the solution called Myproject.Resources. 在名为Myproject.Resources的解决方案中创建一个不同的项目。 Next install Microsoft MAT and manage your translations with MAT: https://developer.microsoft.com/en-us/windows/develop/multilingual-app-toolkit 接下来安装Microsoft MAT并使用MAT管理您的翻译: https : //developer.microsoft.com/zh-cn/windows/develop/multilingual-app-toolkit
You manage your translations with MAT and the .resx files are kept up-to-date. 您可以使用MAT管理翻译,并且.resx文件保持最新状态。 ;-) ;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.