繁体   English   中英

是否可以在发布后脚本中使用带双引号的命令参数?

[英]Is it possible to use a command argument with double quotes in a postpublish script?

我想在我的 ASP.NET Core 项目的postpublish脚本中调用一个命令。 该命令需要一个包含空格并包含在" 。下面是我要运行的所需命令,这在从命令行手动运行时有效:

dotnet nswag webapi2swagger /Assembly:./path/to/assembly.dll /Output:./path/to/swagger.json /InfoTitle:"My API Name" /InfoVersion:v1

在我的project.json此命令包含在 JSON 字符串中。 为了在字符串中使用引号,我用\\转义它们:

"dotnet nswag webapi2swagger /Assembly:%publish:OutputPath%/assembly.dll /Output:%publish:OutputPath%/docs/swagger.json /InfoTitle:\\"My API\\" /InfoVersion:v1"

不幸的是,虽然这会创建一个有效的 JSON 字符串,但在发布后运行的命令似乎实际上解决了转义字符。 因此,传递给InfoTitle的值是\\"My而不是我期望的"My API"

这是一个错误吗? 是否有可能以某种方式在postpublish脚本中以不同的方式转义引号以获得我期望的结果?

我有一个类似的问题,我需要在 postPublish 上运行命令,但在 VS2015 中发布时收到消息“找不到匹配命令“cmd.exe”的可执行文件”。

我最终做的是在项目根目录中创建一个 postPublish.cmd 文件并将其配置为在 project.json 中的 postPublish 上运行,将发布输出文件夹传递给脚本。

    "postpublish": [
        "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%",
        "postPublish.cmd %publish:OutputPath%",
    ]

您将在 postPublish.cmd 脚本中拥有更多控制权,并且不需要转义“路径”,例如:

:: use %1 to access the temp publish folder:
rmdir /s /q "%1\wwwroot\Uploads"

:: The script will be executed at the root of your project. Testing this:
cd >> test.txt
type "project.json" >> testing2.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM