如何在 Azure Service Fabric 中获取文件的文件路径
How to get filepath of a file in Azure Service Fabric
我有一个位于 Azure Service Fabric 解决方案中的项目。如何获取内容文件的特定完整文件路径?内容文件与我的源代码在同一个文件夹中。
我尝试了什么:
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location
但事实证明:
C:\SfDevCluster\Data_App_Node_4\ABCXYZType_App126\ABCXYZPkg.Code.1.0.0\ABCXYZ.dll
这是 bin/debug 文件夹
中的一个文件
要获取内容文件的位置,您可以使用:
var path = Path.Combine(
FabricRuntime.GetActivationContext().GetCodePackageObject("Code").Path,
"Readme.txt");
ServiceEventSource.Current.ServiceMessage(this.Context, File.ReadAllText(path));
前提是文件 Readme.txt 的构建操作设置为 "Content" 并且复制到输出目录设置设置为 "do not copy" 以外的设置。
我有一个位于 Azure Service Fabric 解决方案中的项目。如何获取内容文件的特定完整文件路径?内容文件与我的源代码在同一个文件夹中。
我尝试了什么:
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location
但事实证明:
C:\SfDevCluster\Data_App_Node_4\ABCXYZType_App126\ABCXYZPkg.Code.1.0.0\ABCXYZ.dll 这是 bin/debug 文件夹
中的一个文件要获取内容文件的位置,您可以使用:
var path = Path.Combine(
FabricRuntime.GetActivationContext().GetCodePackageObject("Code").Path,
"Readme.txt");
ServiceEventSource.Current.ServiceMessage(this.Context, File.ReadAllText(path));
前提是文件 Readme.txt 的构建操作设置为 "Content" 并且复制到输出目录设置设置为 "do not copy" 以外的设置。