如何从 Javascript 中读取 Asp.Net 核心程序集版本

How to read the Asp.Net Core Assembly Version from Javascript

我有一个 Asp.Net 核心应用程序。它使用 ReactJS。在 ./ClientApp/public 我有一个名为 configuration.js 的 JS,其中包含:

var configs = {
    "apiUrl": "https://localhost:44356"
}

... 然后在正文部分的 index.html 中:

<body>
<noscript>
    You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script src="configuration.js"></script>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

...(我在 webpack.config.js 中导入它)所以现在反应可以使用 Config.apiUrl。我想在 configuration.js 中添加一个版本变量。并使用 Call .NET methods from JavaScript functions in ASP.NET Core Blazor 中的 DotNet.invokeMethod 之类的内容阅读 javascript 中的 .NET 程序集版本。任何帮助将不胜感激。

放弃获取汇编版本...

阅读完问题 后,我将 REACT_APP_VERSION=$npm_package_version 添加到我的 .env 中。现在,在我的 React 组件中,我可以访问 process.env.REACT_APP_VERSION。我用 npm version patchnpm version minornpm version major 修改我的版本。问题已解决。