微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从 Javascript 读取 Asp.Net Core Assembly 版本

如何解决如何从 Javascript 读取 Asp.Net Core Assembly 版本

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

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

... 然后在 index.html 的 body 部分:

<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 中导入它)所以现在 react 可以使用 Config.apiUrl。我想在 configuration.js 中添加一个版本变量。并使用来自 Call .NET methods from JavaScript functions in ASP.NET Core BlazorDotNet.invokeMethod 之类的东西在 javascript 中读取 .NET 程序集版本。任何帮助将不胜感激。

解决方法

放弃获取汇编版本...

阅读 SO 问题 Get version number from package.json in React Redux (create-react-app) 后,我将 REACT_APP_VERSION=$npm_package_version 添加到我的 .env。现在,在我的 React 组件中,我可以访问 process.env.REACT_APP_VERSION。我用 npm version patchnpm version minornpm version major 撞了我的版本。问题解决了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。