简体   繁体   English

我们可以在 officejs 的清单文件中制作动态 URL 吗?

[英]Can we make dynamic URL in manifest file in officejs?

I am new to office addins.我是办公室插件的新手。 I want to add the environment variable .我想添加环境变量 As in the below manifest code, we can see that the URL http://localhost:3000/ is repeated again and again.在下面的清单代码中,我们可以看到 URL http://localhost:3000/一次又一次地重复。 I want to store this URL in any specific place or in any file and after that, I want to use it in the manifest file.我想将这个 URL 存储在任何特定位置或任何文件中,之后,我想在清单文件中使用它。 So, whenever I change the URL it will reflect all the places .所以,每当我更改 URL 时,它都会反映所有地方 We don't require to change at all.我们根本不需要改变。 I am not getting any idea about it.我对此一无所知。 so can anyone guide me on " How to use a single URL in the manifest with an environment variable? "所以谁能指导我“如何在带有环境变量的清单中使用单个 URL?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="TaskPaneApp">
  <Id>083aced0-1978-4026-bfb3-86e91ecdf2ec</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Test Excel Add-in</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="Test Excel Addin" />
  <Description DefaultValue="A template to get started." />
  <IconUrl DefaultValue="https://localhost:3000/assets/Favicon-36px.jpg" />
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/Favicon-36px.jpg" />
  <SupportUrl DefaultValue="https://test.zendesk.com/hc/en-us" />
  <AppDomains>
    <AppDomain>https://demo.test.test</AppDomain>
    <AppDomain>https://test.test-const.net</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Workbook" />
  </Hosts>
  <DefaultSettings>
    <SourceLocation DefaultValue="https://localhost:3000/taskpane.html" />
  </DefaultSettings>
  <Permissions>ReadWriteDocument</Permissions>
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
    <Hosts>
      <Host xsi:type="Workbook">
        <DesktopFormFactor>
          <GetStarted>
            <Title resid="GetStarted.Title" />
            <Description resid="GetStarted.Description" />
            <LearnMoreUrl resid="GetStarted.LearnMoreUrl" />
          </GetStarted>
          <FunctionFile resid="Commands.Url" />
          <ExtensionPoint xsi:type="PrimaryCommandSurface">
            <OfficeTab id="TabHome">
              <Group id="CommandsGroup">
                <Label resid="CommandsGroup.Label" />
                <Icon>
                  <bt:Image size="16" resid="Icon.16x16" />
                  <bt:Image size="32" resid="Icon.32x32" />
                  <bt:Image size="80" resid="Icon.80x80" />
                </Icon>
                <Control xsi:type="Button" id="TaskpaneButton">
                  <Label resid="TaskpaneButton.Label" />
                  <Supertip>
                    <Title resid="TaskpaneButton.Label" />
                    <Description resid="TaskpaneButton.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Icon.16x16" />
                    <bt:Image size="32" resid="Icon.32x32" />
                    <bt:Image size="80" resid="Icon.80x80" />
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <TaskpaneId>ButtonId1</TaskpaneId>
                    <SourceLocation resid="Taskpane.Url" />
                  </Action>
                </Control>
              </Group>
            </OfficeTab>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/Favicon-36px.jpg" />
        <bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/Favicon-36px.jpg" />
        <bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/Favicon-36px.jpg" />
      </bt:Images>
      <bt:Urls>
        <bt:Url id="GetStarted.LearnMoreUrl" DefaultValue="https://go.microsoft.com/fwlink/?LinkId=276812" />
        <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html" />
        <bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html" />
      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="GetStarted.Title" DefaultValue="Get started with test Add-in" />
        <bt:String id="CommandsGroup.Label" DefaultValue="Commands Group" />
        <bt:String id="TaskpaneButton.Label" DefaultValue="test" />
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="GetStarted.Description" DefaultValue="test Add-in Loaded Successfully" />
        <bt:String id="TaskpaneButton.Tooltip" DefaultValue="test Add-in Taskpane" />
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>

The URLs in the manifest.xml file cannot change after the manifest has been uploaded to Microsoft AppSource (aka "the Store") or uploaded using Centralized Deployment in the Microsoft 365 Admin portal. manifest.xml文件中的 URL 在清单上传到 Microsoft AppSource(也称为“商店”)或使用 Microsoft 365 管理门户中的集中部署上传后无法更改。 It is not possible to store the URLs outside of the manifest.xml file once the manifest has been published or deployed.一旦发布或部署了清单,就不可能将 URL 存储在manifest.xml文件之外。

You can change how the manifest.xml file is generated by modifying the webpack.config.js file in your add-in project by changing the following code:您可以通过修改加载项项目中的webpack.config.js文件来更改manifest.xml文件的生成方式,方法是更改以下代码:

plugins: [
  ...
  new CopyWebpackPlugin({
    patterns: [
      ...
      {
        from: "manifest*.xml",
        to: "[name]" + "[ext]",
        transform(content) {
          if (dev) {
            return content;
          } else {
            return content.toString().replace(new RegExp(urlDev + "(?:public/)?", "g"), urlProd);
          }
        },
      },
    ],
  }),

Typically in Node based applications you could store environment variable in ENV files in the following way:通常在基于节点的应用程序中,您可以通过以下方式将环境变量存储在 ENV 文件中:

# .env file
USER_ID="239482"
USER_KEY="foobar"
NODE_ENV="development"

And read them in your application when required:并在需要时在您的应用程序中阅读它们:

require('dotenv').config();

process.env.USER_ID; // "239482"
process.env.USER_KEY; // "foobar"
process.env.NODE_ENV; // "development"

And you can do so in Office web add-ins.您可以在 Office web 加载项中执行此操作。

But add-in manifest files are processed by the webpack and the final URL depends on the configuration of webpack where you can specify the release and debug URLs and depending the build conditions the required manifest file will produced with the right URL. If you use VSCode and Yeoman generator was used to scaffold the project, in the webpack.config.js file you may find the following declarations:但是加载项清单文件由 webpack 处理,最终的 URL 取决于 webpack 的配置,您可以在其中指定发布和调试 URL,并且根据构建条件,所需的清单文件将使用正确的 URL 生成。如果您使用 VSCode和 Yeoman 生成器用于构建项目,在webpack.config.js文件中,您可以找到以下声明:

const urlDev = "https://localhost:3000/";
const urlProd = "https://www.contoso.com/"; // CHANGE THIS TO YOUR PRODUCTION DEPLOYMENT LOCATION

In the file you may find the code which replaces the localhost entries in your manifest file with the production URL specified in the code (see urlProd ).在该文件中,您可能会找到代码,该代码将清单文件中的本地主机条目替换为代码中指定的生产 URL(请参阅urlProd )。

 new CopyWebpackPlugin({
          patterns: [
            ...
            {
              from: "manifest*.xml",
              to: "[name]" + "[ext]",
              transform(content) {
                if (dev) {
                  return content;
                } else {
                  return content.toString().replace(new RegExp(urlDev, "g"), urlProd);
                }
              },
            },
          ],
        }),

That is done by the webpack. You don't need to replace URLs manually in the manifest file.这是由 webpack 完成的。您无需在清单文件中手动替换 URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何在 django .env 文件中传递动态端口名称 - How can we pass dynamic port names in django .env files 我们如何为邮递员生成动态电子邮件字段和用户名 - How can we generate Dynamic email field and username for postman 我们可以从 Angular 项目中删除 environment.ts 文件吗? - Can we remove environment.ts file from Angular project? 我们可以更改 cypress.env.json 文件名吗 - Can we change the cypress.env.json file name 我们可以将 cmd 中的 output 保存到 txt 文件或环境变量中吗 - Can we save the output in cmd into txt file or environment variables 我们可以在 terraform 资源块上使用作为变量的动态字符串输入吗? - Can we have a dynamic string input with as a variable present on the terraform resource block? 用Gradle将env变量的值写入清单文件 - Gradle-Writing env variable's value to manifest file 如何在.js文件中使用Vue .env设置? - How can I make use of Vue .env settings in a .js file? 动态环境文件扩展名 - dynamic environment file extension 我们如何在 react.js 中正确使用环境变量和 env.config.js 文件(我重新加载后未定义) - how can we use environment variables properly with env.config.js file in react.js(i got undefined after reload)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM