Asp .Net Core项目.json文件

3
我正在尝试创建一个.NET Core项目,它是NETStandard.Library版本1.6.0。我想尝试使用后置构建命令,但我注意到在我们的project.json文件中,可以创建一个"postcompile"脚本。以下是文档链接: https://learn.microsoft.com/en-us/dotnet/articles/core/tools/project-json
我已经创建了一个.cmd文件,并从json文件中调用它,如下所示:
"scripts": {
"postcompile": ["copyFiles.cmd"]

在我的cmd文件中,我可以使用简单的复制命令,它可以正常工作:

xcopy /y "C:\Playground\test.txt" "C:\Playground\test\"

我现在遇到的困难是,我能够在此时访问哪些变量来获取构建输出目录之类的信息?我找不到任何相关的参考资料。谢谢提前帮助。
1个回答

4

您可以使用的完整上下文变量列表,以控制脚本中的流程:

每个脚本块:

%project:Directory%
%project:Name%
%project:Version%

编译特定内容:

%compile:TargetFramework%
%compile:FullTargetFramework%
%compile:Configuration%
%compile:OutputFile%
%compile:OutputDir%
%compile:ResponseFile%
%compile:RuntimeOutputDir% (only available if there is runtime output)
%compile:RuntimeIdentifier% (only availabe if there is runtime output)
%comiple:CompilerExitCode% (only available in the postcompile script block)

发布特定内容:

%publish:ProjectPath%
%publish:Configuration%
%publish:OutputPath%
%publish:TargetFramework%
%publish:FullTargetFramework%
%publish:Runtime%

参考资料:

https://github.com/aspnet/Home/wiki/Project.json-file#scripts

在新的ASP.NET 5项目中根据配置名称设置后构建事件


谢谢,这是一个非常有用的列表。我注意到如果我的脚本直接在json文件中,它们可以正常工作。但是,如果我将我的脚本放入.cmd文件中,它似乎不再知道%compile:OutputDir%是什么了,我的脚本也无法正常工作。你有什么办法让它们在cmd文件中正常工作吗? - C. Moore
抱歉.. 对此一无所知。 - Sanket
不好意思,我最终没有成功让cmd文件工作。 - C. Moore
@C.Moore,你可以通过命令行传递所需的参数,例如 myscript.cmd %compile:OutputDir%,然后在脚本中使用 $1$2 等来访问它们。 - Tomer W

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接