小编Tos*_*Net的帖子

使用 CustomAction 和 Wix 检查是否安装了 .NETCore

如果未安装 NetCore 3.1(预览版),我想取消安装

我创建这个 CustomAction :

using Microsoft.Deployment.WindowsInstaller;
using Microsoft.Win32;

namespace WixCustomAction
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CheckDotNetCore31Installed(Session session)
        {
            session.Log("Begin CheckDotNetCore31Installed");

            RegistryKey lKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost");

            var version = (string)lKey.GetValue("Version");

            session["DOTNETCORE31"] = version == "3.1.0-preview3.19553.2" ? "1" : "0";

            return ActionResult.Success;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在 WXS 文件中:

<<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">

   <Product ...>

  (...)

    <Property Id="DOTNETCORE31">0</Property>

    <Condition Message="You must first install the .NET Core 3.1 Runtime">
      Installed OR DOTNETCORE31="1"
    </Condition>

    <InstallExecuteSequence>
      <Custom Action="Check.NetCore" Before="LaunchConditions">NOT …
Run Code Online (Sandbox Code Playgroud)

c# installation custom-action wix .net-core

5
推荐指数
1
解决办法
5823
查看次数

在本地文件夹中读取/写入内存流

我需要读取和写入我对此方法进行编码的 MemoryStream 但我在加载方法上有一个错误:

    public async void SaveToStorage(MemoryStream stream, String filename)
    {
        var localFolder = ApplicationData.Current.LocalFolder;
        var storageFile = await localFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

        using (Stream x = await storageFile.OpenStreamForWriteAsync())
        {
            x.Seek(0, SeekOrigin.Begin);
            stream.WriteTo(x);
        }
    }
Run Code Online (Sandbox Code Playgroud)

以及出现问题的方法(我认为):

public async Task<MemoryStream> LoadToStorage(string filename)
{
    var localFolder = ApplicationData.Current.LocalFolder;
    var storageFile = await localFolder.GetFileAsync(filename);

    using (var fileStream = await storageFile.OpenStreamForReadAsync())
    {
        using (var memoryStream = new MemoryStream())
        {
            await fileStream.CopyToAsync(memoryStream);

            memoryStream.Seek(0, SeekOrigin.Begin);
            return memoryStream;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

c# storagefile windows-phone-8.1

0
推荐指数
1
解决办法
2086
查看次数