I have a Asp.Net Core App. It uses ReactJS. In ./ClientApp/public I have a JS named configuration.js which contains:
var configs = {
"apiUrl": "https://localhost:44356"
}
... then in index.html in the body section:
<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>
... (I import this in webpack.config.js) so now react can use the Config.apiUrl. I would like to add a version variable in configuration.js. And read the .NET assembly version in javascript with something like DotNet.invokeMethod from Call .NET methods from JavaScript functions in ASP.NET Core Blazor. Any help would be appreciated.
DotNet.invokeMethodis from Blazor and can't be used in React. Besides, I think you might confuse different concepts here. I guess ASP.NET core is used for hosting your application - serving the requested js files for react to run. So, if you build react, it is built without dotnet being involved. Sure, you could pass a variable into the build process, but this would only reflect the .net version of the built agent, not the host. If you want to display the version of the server, you would need to create an API endpoint that is then called by your react app.