space-leak 相关问题


带有空格的列名称 - Athena

我正在尝试使用 Athena 控制台创建一个列名称为 Space 的表。 示例:“Mag Creative”字符串 错误:此字段为必填字段。不允许有空格!


flink sql 作业抛出 no space left 异常,尽管有足够的空间可用

Flink 版本:1.17.1 环境:EKS Flink Kubernetes Operator Flink SQL 作业,rocksdb 后端的检查点状态小于 10GB。 我们将实例类型从 m5d.2xlarge 更改为 r5d.xl...


带有边框半径和粘性标题的 HTML 表格

我有一个 HTML ,带有边框半径和使用位置的粘性标题:sticky,如下所示: https://codepen.io/muhammadrehansaeed/pen/OJpeeKP 但是,当使用 滚动时 我有一个带有 <table> 的 HTML border-radius 和使用 position: sticky 的粘性标题,如下所示: https://codepen.io/muhammadrehansaeed/pen/OJpeeKP 但是,当使用粘性标题滚动时,表格行会伸出粘性标题的圆角所在的位置。请参阅此图片的左上角: 有没有办法可以在使用粘性标题向下滚动时保持圆角,或者在标题变得粘性并从原始位置向下移动时删除粘性标题?理想情况下,我想要一个CSS解决方案。 您可以使用伪元素隐藏边框的某些部分: table thead th:first-child::before, table thead th:last-child::after { width: 1px; height: 5px; background: white; content: ""; display: block; position: absolute; top: 0px; } table thead th:first-child::before { left: -1px; } table thead th:last-child::after { right: -1px; } 正如Ivan建议的那样,似乎使用伪元素来覆盖标题下方不需要的边框是(令人惊讶的)唯一可行的选择。我建议使用伪不仅用于覆盖“外部”区域,而且还用于绘制弧线和填充“内部”区域。可以使用堆叠背景来做到这一点。应用于原始代码: /* § Additions / Changes */ table thead th { position: relative; } /* Pseudos exceeding header boundary by border width; with rectangle covering half circle and rest of height */ table thead th:last-child::after, table thead th:first-child::before { content: ""; position: absolute; top: 0; bottom: 0; left: calc(-1 * var(--global-border-width-1)); width: var(--global-border-radius); background-image: linear-gradient(to bottom, transparent var(--global-border-radius), var(--global-title-color) 0), radial-gradient(circle at var(--global-border-radius) var(--global-border-radius), var(--global-title-color) var(--global-border-radius), var(--global-content-background-color) 0); background-position: top left; background-size: var(--global-border-diameter) 100%, var(--global-border-diameter) var(--global-border-diameter); background-repeat: no-repeat; } table thead th:last-child::after { left: auto; right: calc(-1 * var(--global-border-width-1)); background-position: top right; } /* § Declarations and original style */ html { --global-content-background-color: white; --global-title-color: black; --global-background-color: lightblue; --global-border-color: black; --global-border-radius: 20px; --global-border-width-1: 10px; --global-space-fixed-2: 10px; --global-space-fixed-3: 15px; --global-border-diameter: calc(2 * var(--global-border-radius)); background-color: var(--global-content-background-color); } table { color: var(--global-title-color); background-color: var(--global-content-background-color); border-collapse: separate; border-color: var(--global-title-color); border-style: solid; border-radius: var(--global-border-radius); border-width: 0 var(--global-border-width-1) var(--global-border-width-1) var(--global-border-width-1); border-spacing: 0; width: 100%; } table thead { position: sticky; top: 0; z-index: 10; } table thead th { color: var(--global-background-color); background-color: var(--global-title-color); padding: var(--global-space-fixed-2) var(--global-space-fixed-3); vertical-align: bottom; } table tbody td { border-top: var(--global-border-width-1) solid var(--global-border-color); padding: var(--global-space-fixed-2) var(--global-space-fixed-3); vertical-align: top; } table tbody tr:last-child td:first-child { border-bottom-left-radius: var(--global-border-radius); } table tbody tr:last-child td:last-child { border-bottom-right-radius: var(--global-border-radius); } /* § Unrelated / demo */ * { scroll-margin-top: calc(var(--global-space-fixed-2) * 4 + 1rem); /* = height of sticky thead + top padding of cell, provided text in thead does not wrap */ scroll-margin-bottom: 1em; } td { height: 60vh; } td a { float: right } tr:last-child td { vertical-align: bottom; } a[name]:empty::before { content: attr(name); } th:not(#\0):hover::before { background-image: linear-gradient(to bottom, transparent var(--global-border-radius), #0F08 0), radial-gradient(circle at center, #00F8 var(--global-border-radius), #F2F4 0); background-position: top left; background-size: var(--global-border-diameter) 100%, var(--global-border-diameter) var(--global-border-diameter); } <table> <thead> <tr> <th>Fake non-transparent "border-radius"</th> </tr> </thead> <tbody> <tr> <td> <a href="#⬆️" name="⬇️"></a> For fixed header</td> </tr> <tr> <td> <a href="#⬇️" name="⬆️"></a> Using CSS stacked background images in pseudo elements</td> </tr> </tbody> </table> 只需从表格中删除边框,并为表格主体中的第一个和最后一个表格单元格添加左右边框: tbody td:first-child { border-left: 1px solid black; } tbody td:last-child { border-right: 1px solid black; } tbody tr:last-child td{ border-bottom: 1px solid black; } tbody tr:last-child td:first-child { border-bottom-left-radius: 2px; } tbody tr:last-child td:last-child { border-bottom-right-radius: 2px; } 当然是使用适当的缩进、嵌套和变量! 使用许多伪选择器看起来样式相当丑陋,但似乎可以解决您的问题。 有一个更紧凑的解决方案。只需将具有背景颜色的框阴影添加到第一个 < th > 和最后一个 < th > 即可隐藏元素。 在此示例中,在右侧,您可以看到表格行由于边框半径而可见。在左边,我应用了盒子阴影。 盒子阴影:0 -2.1rem 0 .6rem #E5E7EB; 在这里,它是灰色的,以便您可以看到它的工作原理,但您只需使用与背景相同的颜色即可使其完全不可见。 这是最终结果以及我正在使用的代码: th:第一个孩子 { 边界半径:0.75rem 0 0 0; 左边框:.1rem 实心 $color-gray-200; 框阴影:0 -2.1rem 0 .6rem $color-gray-200; } th:最后一个孩子{ 边界半径:0 0.75rem 0 0; 右边框:.1rem 实心 $color-gray-200; 盒子阴影:1rem -2.1rem 0 .6rem $颜色白色; } 可能需要调整框阴影以隐藏基于所选边框半径的行。 不确定你是否熟悉jquery,如果熟悉的话你可以在滚动内容时动态更改 border-top-left-radius: 等于粘性标题的半径,但这对于新手来说有点棘手jquery/JS。 其次,您可以将粘性标题封闭到父级(例如class="parent")),并将父级背景设置为白色,没有边框。并保持粘性标题的边框半径不变。因此,当您滚动内容时将位于该父级下方(例如 class="parent")。为了确保父级出现在该行上方,您可以给出 z-index: 10


NextJS 中 useFormStatus() 始终为 false

我尝试使用 useFormStatus() 在提交表单并等待获取数据时动态更改 UI。 我有一个像这样的表单组件 函数 onSubmit(数据:z.infer 我正在尝试使用 useFormStatus() 在提交表单并等待获取数据时动态更改 UI。 我有一个像这样的表单组件 function onSubmit(data: z.infer<typeof FormSchema>) { requestImg(data).then((imageStringify) => { const binaryData = Buffer.from(imageStringify.image); const imageBase64 = URL.createObjectURL( new Blob([binaryData.buffer], { type: "image/jpeg" } /* (1) */) ); setOpen(true); setSource(imageBase64); }); } if (isDesktop) { return ( <Form {...form}> <form onSubmit={form.handleSubmit(onSubmit)} className="w-2/3 space-y-6" > ... 其中 requestImg(data) 是服务器操作。 然后,我将 Button 组件嵌套在不同的 Button.tsx 文件中的 <form> 中 import { useFormStatus } from "react-dom"; import { Button } from "@/components/ui/button"; export default function ButtonSub() { const { pending } = useFormStatus(); console.log(pending); return ( <Button className="w-full" type="submit" aria-disabled={pending}> {pending ? "Processing..." : "Submit"} </Button> ); } 问题是,当我单击提交时,按钮文本不会更改为“正在处理...” 编辑 似乎仅当您在表单上使用操作关键字时才有效。我试过了 <form action={async (formData: FormData) => { requestImg(formData).then((imageStringify) => { const binaryData = Buffer.from(imageStringify.image); const imageBase64 = URL.createObjectURL( new Blob([binaryData.buffer], { type: "image/jpeg" } /* (1) */) ); setSource(imageBase64); setOpen(true); }); }} className="w-2/3 space-y-6" > 但是现在使用 byte8Array 生成的图像已损坏。 我有一个带有动态 src 的图像,其中充满了 const [source, setSource] = useState(""); <img src={source}/> 似乎只有在您使用 action 关键字时才有效 形式。 确实如此。 useFormStatus 必须在表单的子组件内使用,它可以监视服务器操作的状态变化。但据我所知,它会监听 action。 action 定义提交后表单数据的服务器端目的地。在服务器操作的上下文中,服务器操作向当前 URL 发出 post 请求。所以它没有监听表单 onSubmit,这就是为什么你的第一个代码执行不起作用。 现在服务器操作在服务器上下文中运行,它们在服务器上执行,但setState是客户端特定的代码


如何使用 XSLT 删除基于值的特定 XML 元素

假设我们有要转换的 XML: 测试 / 假设我们有要转换的 XML: <?xml version="1.0" encoding="UTF-8"?> <node> <field1>test</field1> <field2>/</field2> <field3>test2</field3> <field4>/<field4> </node> 我想使用 XSLT 1.0 对其进行转换,以便复制整个结构和所有值,除了具有值“/”的元素。 到目前为止,我已经找到了这个,我认为这离我需要的并不遥远,但它还没有工作。 <xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:strip-space elements="*"/> <xsl:output indent="yes"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="//text()='/'" /> </xsl:transform> 所以我期望的输出是这样的: <?xml version="1.0" encoding="UTF-8"?> <node> <field1>test</field1> <field3>test2</field3> </node> 尝试此操作时,我收到未指定的错误(因为我正在使用免费的在线工具进行转换)。 //text()='/' 不是有效的位置路径。 在任何情况下,您想要删除元素,而不是文本节点 - 所以您应该使用类似的东西: <xsl:template match="*[.='/']" />


如何在React Prime DataTable中添加超链接?

我有一个数据表,我正在使用 React prime 库, 我的要求是在一个特定列中添加一个链接。 我有一个数据表,我正在使用 React prime 库, 我的要求是在一个特定列中添加一个链接。 <DataTable paginator rows={tableRowPage} value={products} tableStyle={{ minWidth: "30rem" }} ><Column key={field} field={field} header={header} style={{ width: "25%" }} /> </DataTable> 我需要特定单元格中的超链接 我在数据表中遇到了同样的问题,不幸的是,根据我的研究,他们似乎不提供对此的支持。 但是,我已经设法通过这种方式解决了这个问题: 数据表添加链接逻辑: <Column field="code" header="Code" body={(rowData) => { return ( <div sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", }} > <div style={{ color: "#3F00FF", textDecoration: "underline", cursor: "pointer", "&:hover": { color: "#23297A", }, }} onClick={() => window.open("www.google.com", "_blank").focus()} > {rowData.code} </div> </div> ); }} ></Column>; 我已经使用 Prime React Column 组件中的 body 渲染了数据。我应用 CSS 将其设置为链接样式,并添加了 onClick 事件以进行重定向。您可以根据您的要求修改逻辑。 完整代码链接:https://codesandbox.io/s/primereact-demo-forked-kqtdvs?file=/src/App.jsx 如果您还有任何疑问,请告诉我。


显示多行文本的正确方法是什么?

我有一个 HTML 文档,其中有一些不同的文本行,是否有一些确定的正确方法来显示它们? 例子: 这里有 一些线路 文本的 我应该为每一行使用 标签,还是...... 我有一个 HTML 文档,其中包含一些不同的文本行,是否有一些确定的正确方法来显示它们? 示例: Here are some lines of text 我应该为每一行使用 <p> 标签,还是有其他/更好的方法来做到这一点? 示例: <p>Here are</p> <p>some lines</p> <p>of text</p> 或 <p> Here are <br> some lines <br> of text <br> </p> 或者完全不同的东西? CSS 和其他东西目前并不真正相关,我只是想知道哪种是“最正确”的使用方式。 如果您想在 div 中显示包含新行的字符串,则可以使用 white-space: pre-wrap css 样式: .multiline { white-space: pre-wrap; } <div class="multiline"> A multiline text for demo purpose </div> 或者你可以尝试this而不用标签换行每行: <div style="white-space:pre"> Here are some lines of text </div> 正确的做事方法是使用为你需要的东西而制作的东西。 如果您想要换行(输入),请使用 <br>; 如果要定义段落,请使用 <p>。 根据this,<br>元素用于插入换行符而不开始新段落。因此,与第一个解决方案相比,您应该更喜欢第二个解决方案。 w3schools 附带了一篇关于风格指南和编码约定的精彩文章。 规范非常清楚地表明,永远不要使用<br>,除非换行符实际上是形成单个文本单元的内容的一部分。 由于这些是不同的文本行,而不是恰好包含换行符的单个单元,因此需要将它们拆分为单独的 <p> 元素。 不存在最正确的方式,至少根据您当前的需求规范。是的,您可以使用 <p></p> 标签将它们全部放在单独的段落中,或者您可以通过每行的 <br> 标签将它们分开。您还可以将 span 与空白 CSS 属性结合使用,这样您就有很多选择。要选择最适合您的选项,您需要尝试一下,看看什么最适合您的要求。 如果您想创建一个多行段落来保持代码中的行分隔,而不到处乱扔。只需使用 html 标签即可。 使用 <pre> 标签就是您想要的: <pre> Text in a pre element is displayed in a fixed-width font, and it preserves both spaces and line breaks </pre> “pre”代表“预格式化文本” https://www.w3schools.com/tags/tag_pre.asp


如何使整个跨度落入新行?

这个片段显示了我想要的: http://jsfiddle.net/945Df/3/ 阿根廷圣达菲罗萨里奥。 这个片段显示了我想要的: http://jsfiddle.net/945Df/3/ <div class="sup" id="pr"> <strong> <a href="#">Rosario, Santa Fe, Argentina.</a> <span class="date">17 de septiembre de 2013.</span></strong> </div> <div class="sup"> <strong> <a href="#">Rosario, Santa Fe, Argentina.</a> <span class="date">17 de septiembre de 2013.</span> </strong> </div> 当div的宽度(在项目中,视口)没有更多空间时,我希望跨度落入新行。 抱歉我的解释不好。我不知道该怎么做。谢谢! 编辑:在第二个示例中,短语“SEPTIEMBRE DE 2013”。落入新行。但“17 DE”字样仍位于上行。我想要“2013 年 9 月 17 日”。落入新行。明白了吗? 如果您希望跨度不换行,而是完全移动到其他文本下方,您可以使用 white-space: nowrap; .date { text-transform: uppercase; color:#848484; white-space:nowrap; } 演示 要让span在空间不足时跳到下一行,可以设置为display: inline-block; .date { display: inline-block; ... } 检查这个:http://jsfiddle.net/945Df/7/ 这就是我实现它的方法: #spantomovedown{ clear: both; display: inline-block; width: 100%; } .date{display:inline-block;} 当日期比div长时,换行显示 示例:http://jsfiddle.net/TqRyK/ 如果你漂浮:对;当不再有空间容纳整个内容时,它应该落到下一行。 之后您将需要一个清除元件。 我通过以下方式实现了它 word-wrap: break word;


表单响应:“无法处理请求 HTTP ERROR 500”。我做错了什么?

我尝试在网站上编写 php 表单,但收到错误 500。我无法弄清楚我做错了什么。你能看一下代码看看我做错了什么吗? PHP: 我尝试在网站上编写 php 表单,但收到错误 500。我无法弄清楚我做错了什么。你能看一下代码看看我做错了什么吗? PHP: <?php // define variables and set to empty values $name = $email = $phone = $enquiry = ""; if ( $_SERVER[ "REQUEST_METHOD" ] == "POST" ) { if ( empty( $_POST[ "name" ] ) ) { $nameErr = "Name is required"; } else { $name = test_input( $_POST[ "name" ] ); // check if name only contains letters and whitespace if ( !preg_match( "/^[a-zA-Z-' ]*$/", $name ) ) { $nameErr = "Only letters and white space allowed"; } } if ( empty( $_POST[ "email" ] ) ) { $emailErr = "Email is required"; } else { $email = test_input( $_POST[ "email" ] ); // check if e-mail address is well-formed if ( !filter_var( $email, FILTER_VALIDATE_EMAIL ) ) { $emailErr = "Invalid email format"; } } if ( empty( $_POST[ "phone" ] ) ) { $comment = ""; } else { $comment = test_input( $_POST[ "phone" ] ); } if ( empty( $_POST[ "enquiry" ] ) ) { $comment = ""; } else { $comment = test_input( $_POST[ "enquiry" ] ); } } // Create the email and send the message $destination = "[email protected]"; $subject = "Website Contact Form Enquiry: $name"; $body = "You have received a new message from your website contact form.\\n\\n"."Here are the details:\\n\\nName: $name\\n\\nEmail: $email\\n\\nPhone: $phone\\n\\nEnquiry:\\n$enquiry"; $header = "From: [email protected]\\n"; $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/plain; charset=iso-8859-1"; $headers[] = "From: " . $fromAddress; $headers[] = "Subject: " . $subject; $headers[] = "X-Mailer: PHP/".phpversion(); mail($destination, $subject, $message, implode("\r\n", $headers)); // mail($to,$subject,$msg,$headers); echo "Email successfully sent."; ?> HTML 格式: <form id="contact-form" method="post" action="/contact.php" role="form"> <div class="messages"></div> <div class="controls"> <div class="row"> <div class="col-md-10"> <div class="form-group"> <input id="form_name" type="text" name="name" class="form-control" placeholder="Name*" required="required" data-error="Your name is required." > <div class="help-block with-errors"></div> </div> </div> <div class="col-md-10"> <div class="form-group"> <input id="form_email" type="email" name="email" class="form-control" placeholder="Email*" required="required" data-error="Valid email is required." > <div class="help-block with-errors"></div> </div> </div> <div class="col-md-10"> <div class="form-group"> <input id="form_phone" type="text" name="phone" class="form-control" placeholder="Phone" > <div class="help-block with-errors"></div> </div> </div> </div> <div class="row"> <div class="col-md-10"> <div class="form-group"> <textarea id="form_enquiry" name="enquiry" class="form-control" placeholder="Enquiry*" rows="6" required="required" data-error="Please, leave us a message."></textarea> <div class="help-block with-errors"></div> </div> </div> <div class="col-md-12"> <input class="btn btn-large btn-primary centre mt-10" type="submit" value="Submit" > </div> </div> </div> </form> 我已按照其他人的指示使表单正常工作,但所做的更改仍然会出现错误。 这是一个简单的形式,但我似乎对我做错了什么缺乏了解。 请帮助我。 如果您查看发送邮件的行,这是一个硬行结尾,将 $headers 推到新行上吗?这将调用 500 错误。 查看 /var/log/apache2/error.log(如果您使用的是 Debian)或 /var/log/httpd/error.log(如果使用的是 RHEL 或类似系统)。 您的代码存在许多问题,但首先关注快乐的道路,然后让事情正常运行。


MatToolbar:尝试组合不同的工具栏模式

出现以下错误: MatToolbar:尝试组合不同的工具栏模式。显式指定多个 元素或仅将内容放置在 中 出现以下错误: MatToolbar:尝试组合不同的工具栏模式。要么显式指定多个 <mat-toolbar-row> 元素,要么仅将内容放置在单行的 <mat-toolbar> 中。 我的代码已经在 mat-toolbar 中应用了 mat-toolbar-row。然而,该错误仍然存在。 html文件的代码片段如下: <div class="wallpaper"> <mat-toolbar color="primary"> <mat-toolbar-row> <span>Welcome, User</span> <span class="example-fill-remaining-space"></span> <span class="align-center"></span> <span class="example-spacer"></span> <button mat-button>Create Incident </button> <a [routerLink]="['/closed']"><button mat-button style="color: white">Closed Incident</button></a> <span class="example-spacer"></span> <a [routerLink]="['/login']"><button mat-button>Logout</button></a> <img src="../../assets/hsbc_logo3.png" class="logo-hsbc"/> </mat-toolbar-row> <h1>INCIDENT MANAGEMENT SYSTEM</h1> </mat-toolbar> <h1>Welcome to Incident Management System</h1> <mat-card style="background: transparent"> <!-- Title of an Card --> <mat-card-title>Incident Details</mat-card-title> <mat-card-content> <form> <table > <tr> <td> <mat-form-field class="demo-full-width"> <mat-label >Description</mat-label> <textarea [(ngModel)]="incident.description" name="description" cdkTextareaAutosize cdkAutosizeMinRows="1" cdkAutosizeMaxRows="5" matInput></textarea> </mat-form-field> </td> <td> <h4>{{message}}</h4> </td> </tr> <tr> <td> <mat-form-field class="demo-full-width"> <input matInput [matDatepicker]="picker" placeholder="Incident Date" [(ngModel)]="incident.date" name="date" > <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle> <mat-datepicker touchUi="true" #picker></mat-datepicker> </mat-form-field> </td> </tr> <tr> <td colspan="2"> <mat-form-field class="demo-full-width"> <input matInput placeholder="Incident Category" [(ngModel)]="incident.category" name="category"> </mat-form-field> </td> </tr> <tr> <td > <mat-form-field class="demo-full-width"> <mat-select placeholder="Application Owner" [(ngModel)]="incident.owner" name="owner"> <mat-option style="background-color:grey">-- Select--</mat-option> <mat-option style="background-color:cornsilk" value="1">BRV</mat-option> <mat-option style="background-color:cornsilk" value="2">FRTB</mat-option> <mat-option style="background-color:cornsilk" value="3">FSA</mat-option> </mat-select> </mat-form-field> </td> <td> <mat-form-field> <mat-select placeholder="Symphony Group" [(ngModel)]="incident.symphony_group" name="symphony_group"> <mat-option style="background-color:grey">-- Select --</mat-option> <mat-option style="background-color:cornsilk" value="1">MMO SheHacks</mat-option> <mat-option style="background-color: cornsilk" value="2">MMO IT INDIA</mat-option> </mat-select> </mat-form-field> </td> </tr> <tr> <td> <mat-form-field> <mat-select placeholder="Application" [(ngModel)]="incident.application" name="application"> <mat-option style="background-color:grey">-- Select--</mat-option> <mat-option style="background-color:cornsilk" value="1">BRV</mat-option> <mat-option style="background-color:cornsilk" value="2">FRTB</mat-option> <mat-option style="background-color:cornsilk" value="3">FSA</mat-option> </mat-select> </mat-form-field> </td> <td> <mat-form-field> <mat-select placeholder="Status" [(value)]="status" [(ngModel)]="incident.status" name="status"> <mat-option style="background-color:grey">-- Select --</mat-option> <mat-option style="background-color: green" value="1">Available</mat-option> <mat-option style="background-color: orange" value="2">Reduced</mat-option> <mat-option style="background-color: red" value="3">Unavailable</mat-option> </mat-select> </mat-form-field> </td> </tr> <tr> <td colspan="2"> </td> </tr> <tr> <td colspan="2" class="content-center"> <button style="margin:5px" mat-raised-button color="accent" (click)="submit()">Submit Incident</button> <button style="margin:5px" mat-raised-button color="accent" (click)="reset()">Clear</button> <button style="margin:5px" mat-raised-button color="accent">Raise BGCR</button> <button style="margin:5px" mat-raised-button color="accent">Raise Jira</button> </td> </tr> </table> </form> </mat-card-content> </mat-card> </div> 您需要移除 <h1>INCIDENT MANAGEMENT SYSTEM</h1> 或将其放入 <mat-toolbar-row> 内。 我无法在垫子工具栏中填充图像 有什么帮助吗?


如何在C#中正确导入不同项目的Proto文件?

我的解决方案中有 2 个项目 /Common/Common.csproj /数据/Data.csproj 我的 Data.csproj 中有一个 Proto 文件: 我的解决方案中有 2 个项目 /通用/Common.csproj /数据/Data.csproj 我的 Data.csproj 中有一个 Proto 文件: <Protobuf Include=".\Protos\UserService.proto" GrpcServices="Server" /> 看起来像这样: service UserService { rpc AddUser (UserRequest) returns (SimpleResponse); } .... 现在应该从 Common 导入 SimpleReponse,所以我在这个项目中的路径 /Common/Protos/common.proto 中创建了一个 common.proto,我想导入它: 导入“common.proto”; 服务用户服务{ rpc AddUser(UserRequest) 返回(SimpleResponse); } .... 然后 Rider 显示 SimpleResponse 仍为红色,以及 common.proto 导入。当我快捷键 Space + .它会向我显示我所做的“添加到原始导入”。 因此,在全局设置中,路径现在已正确设置 - 原型和响应不再是红色,我可以按 F12 来查看它们。当我现在尝试构建时,我仍然收到错误: 我尝试在csproj中添加路径 <Protobuf Include="..\Common\Protos\common.proto" Link="..\Common\Protos\common.proto" /> 但仍然是同样的错误。 有什么想法吗? 从不同项目导入原始文件非常棘手,我发现这个解决方案非常费力。所以我想与社区分享 我正在使用微服务架构,我希望我的消息 ProtoFiles 应该在 SharedProto 项目中并在不同的项目中使用它们 假设我在 SharedProto 中有消息 Proto 文件 SharedProto --Protos ----company_dto.proto ----branch_dto.proto ---- ... company_dto.proto的内容 syntax = "proto3"; option csharp_namespace = "SharedProto.Protos"; package sharedproto.protos; // *** DTO message CompanyDto { int32 Id = 1; string Code = 2; string Name = 3; string Logo = 4; string Website = 5; } SharedProto.csproj 的内容 .... <ItemGroup> <Protobuf Include="Protos\company_dto.proto" GrpcServices="None"> <Protobuf Include="Protos\branch_dto.proto" GrpcServices="None"> </ItemGroup> .... 我拥有服务原型的项目组织 Organization ... --Protos ----company_rpc.proto ----branch_rpc.proto ... 我想将 comapany_dto.proto(属于 SharedProto 项目的一部分)导入到 comapany_rpc.proto(属于 Organization 项目的一部分)。让我们看看 .csproj 文件,因为所有的技巧都在这里: 组织.csproj的内容 <ItemGroup> <ProjectReference Include="..\SharedProto\SharedProto.csproj"> <GlobalPropertiesToRemove></GlobalPropertiesToRemove> </ProjectReference> </ItemGroup> <ItemGroup> <!-- DTOs --> <Protobuf Include="..\SharedProto\Protos\company_dto.proto" ProtoRoot=".." GrpcServices="None" Link="Protos\company_dto.proto" /> <Protobuf Include="Protos\company_rpc.proto" AdditionalImportDirs="../SharedProto" GrpcServices="Server" /> </ItemGroup> 如果您看到上面的 Organzation.csproj 文件,那么您需要了解一些非常重要的要点,以避免 file not found error 从其他项目导入 proto 文件。 ProtoRoot=".." 和 Link="Protos\company_dto.proto" 之后,将此 AdditionalImportDirs="../SharedProto" 添加到要导入文件的 <Protobuf Include=.... 上。但是,在这些设置之后,您可以在其他项目中导入 SharedProto 文件,在我的例子中它是组织项目。看看吧 company_rpc.proto内容 syntax = "proto3"; import "google/protobuf/empty.proto"; import "Protos/company_dto.proto"; package organization.companyrpc; // *** Rpc-Service service CompanyRpcService { // Retrieve All rpc GetAllCompanies (google.protobuf.Empty) returns (GetCompanyListResponse){ } .... } // Response: Retrieve All message GetCompanyListResponse { repeated sharedproto.protos.CompanyDto DtoRows = 1; string Message = 2; } 如果您看到我的company_rpc.proto文件,您就会了解我如何导入它(import "Protos/company_dto.proto";)以及我如何使用它(sharedproto.protos.CompanyDto DtoRows) 记住这个sharedproto.protos来自company_dto.proto文件中的包名称 上述设置适用于我的 .net core grpc 2.60.0 和 .net core 8


© www.soinside.com 2019 - 2024. All rights reserved.