我正在构建一个只为Windows的应用程序,这需要使用.Net毛伊岛消费一个docx文件.
我使用了建议的类IFilePicker,实现了它,并且在调试时工作得很好(在调试和发布模式下都是如此).
因此,在完成一个预览版之后,我希望使用以下工具"像便携版本一样"部署未打包的版本:
MSBuild.exe D:\Workspace\dotNet\WordReplacer\WordReplacer.App\ /restore /t:Publish /p:TargetFramework=net6.0-windows10.0.19041 /p:configuration=release /p:WindowsAppSDKSelfContained=true /p:Platform=x64 /p:PublishSingleFile=true /p:WindowsPackageType=None /p:RuntimeIdentifier=win10-x64
除了FilePicker不工作并给出错误之外,一切都像调试一样工作得很好:
值不在预期范围内
如果我安装的是带有证书的已发布包,则不会发生此错误.因此,也许我在生成解压应用程序的msBuilder解决方案中遗漏了一些东西.
我使用的是社区工具包.MVVM,我用来挑选文件的方法保留在我的视图模型中:
private string _inputFilePath;
[ObservableProperty]
private string _inputFileNameText = "Select a input file";
[RelayCommand]
public async Task PickInputDocAsync()
{
try
{
var customFileType = new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.WinUI, new[] { ".doc", ".docx" } },
});
PickOptions options = new()
{
PickerTitle = "Please select a document",
FileTypes = customFileType,
};
var result = await FilePicker.Default.PickAsync(options).ConfigureAwait(false);
if (result != null)
{
_inputFilePath = result.FullPath;
InputFileNameText = result.FileName;
}
}
catch (Exception ex)
{
ErrorMessage = $"{ex.InnerException?.Message} Error: {ex.Message}, InputFilePath: {_inputFilePath}, InputFileName: {InputFileNameText}";
}
有什么办法修好它吗?