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

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

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

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

我尝试使用脚本名称作为prebuild命令运行脚本,在此构建中确定脚本的扩展名。

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

Visual Studio中的预构建版本:

python generate.py

python脚本:

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>

这为我解决了问题

Python Pandas导出数据 - python

我正在使用python pandas处理一些数据。我已使用以下代码将数据导出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…

Python-crontab模块 - python

我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…

如何在python脚本中更改Linux目录? - python

当前,我正在使用python脚本在Linux shell中运行命令。当我更改目录时,它似乎不起作用(当我运行命令ls时,它列出了初始目录的文件)。我想将目录更改为桌面。我的代码:import os os.popen("cd Desktop") d = os.popen("ls") x = d.read() print …

Python:在不更改段落顺序的情况下在文件的每个段落中反向单词? - python

我想通过反转text_in.txt文件中的单词来生成text_out.txt文件,如下所示:text_in.txt具有两段,如下所示:Hello world, I am Here. I am eighteen years old. text_out.txt应该是这样的:Here. am I world, Hello old. years eighteen a…

用大写字母拆分字符串,但忽略AAA Python Regex - python

我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…