繁体   English   中英

在预构建中生成代码的问题

[英]Problem with generating code in pre-build

对于我的项目,我需要为 GRPC 自动生成代码。 我使用 .bat/.sh 文件生成此代码。

但是当我在预构建中生成代码时,代码失败,因为它包含错误。

然后所有错误都显示 op,但它们很快就消失了,因为现在它正在查找生成的代码并且没有错误。

我尝试使用脚本名称作为预构建命令运行脚本,其中构建决定了脚本的扩展名。

我也尝试从 python 运行命令,甚至在生成完成后添加睡眠,但遗憾的是没有任何效果。

Visual Studio 中的预构建脚本:

python generate.py

蟒蛇脚本:

import sys
import os
import time
print("Working dir: " + os.getcwd())
if("win" in sys.platform):
    os.system('generate.bat')
else:
    os.system("bash \"" + os.path.dirname(os.path.realpath(__file__)) + '/generate.sh' + "\"")
print("done installing")
time.sleep(5)
print("done finalising")

构建输出:

1>done installing
1>done finalising
1>CSharp\TimelineEvents.cs(18,32,18,48): error CS0246: The type or namespace name 'PayloadOneofCase' could not be found (are you missing a using directive or an assembly reference?)
1>CSharp\FrontendEndpointGrpc.cs(28,31,28,51): error CS0246: The type or namespace name 'RegisterFileResponse' could not be found (are you missing a using directive or an assembly reference?)
1>Done building project "Protocol.csproj" -- FAILED.

我希望构建等待预构建,但情况似乎并非如此,因为当您第一次运行生成时构建失败,但是当我再次构建它时它运行得很好

我通过更改项目文件解决了这个问题:

  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="python generate.py" />

对此:

  <Target Name="Generate" BeforeTargets="BeforeBuild">
    <Message Text="Generating GRPC code" />
    <Exec Command="python generate.py" />
    <ItemGroup>
      <Compile Include="CSharp\**\*.cs" />
    </ItemGroup>

这为我解决了问题

暂无
暂无

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

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