【问题标题】:how to use the absolute path in the msbuild config file(*.proj)?msbuild配置文件(*.proj)中如何使用绝对路径?
【发布时间】:2018-07-15 05:45:35
【问题描述】:

msbuild.proj 文件中的相关内容:

<Message Text="*****check the site exists*****" Importance="high"/>
<Exec Command="C:\WINDOWS\System32\inetsrv\appcmd.exe list site /name:$(WebAppSiteName) " ContinueOnError="true">
  <Output TaskParameter="ExitCode" PropertyName="ErrorCode2" />
</Exec>

<Message Text="*****if not exists create site*****" Importance="high"  Condition="'$(ErrorCode2)' > '0'" />
<Exec Command="C:\WINDOWS\System32\inetsrv\appcmd.exe add site /name:$(WebAppSiteName) /bindings:http/*:80:$(SiteDomain) /applicationDefaults.applicationPool:$(WebAppSiteName) /physicalPath:$(BuildSolutionDir)$(DeployDir)Website" Condition="$(WebAppSiteName)!=''  and '$(ErrorCode2)' > '0'"></Exec>

上图:runtime的实际参数(/physicalPath)值为: D:\YDJWebsite.Dev\deply\fw\..\..\mkltest2Website

其实上面的路径等价于D:\YDJWebsite.Dev\mkltest2Website

访问该站点时,错误显示: 500内部服务器错误, 找不到资源

如果我将路径更改为正确的格式“D:\YDJWebsite.Dev\mkltest2Website”,错误就消失了

the physical path of website in iis shows here.

现在,我知道唯一的解决方案是将参数值(/physicalPath)转换为正确的格式?

但是如何在 proj 文件中做到这一点?有什么建议吗?谢谢。

【问题讨论】:

    标签: msbuild appcmd


    【解决方案1】:

    我已经解决了 msbuild 的内联任务的问题。

    <UsingTask TaskName="AbsolutePath" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
      <ParameterGroup>
          <Path ParameterType="System.String" Required="true" />
          <FullPath ParameterType="System.String" Output="true" />  
      </ParameterGroup>
      <Task>
          <Reference Include="System.Core" />
          <Using Namespace="System" />
          <Using Namespace="System.IO" />
          <Using Namespace="System.Text.RegularExpressions" />
          <Using Namespace="Microsoft.Build.Framework" />
          <Using Namespace="Microsoft.Build.Utilities" />
          <Code Type="Fragment" Language="cs">
              <![CDATA[
              try {
                    if(string.IsNullOrWhiteSpace(Path))
                    {
                        FullPath = "";
                    }
                    else
                    {
                        DirectoryInfo dirInfo = new DirectoryInfo(Path);
                        FullPath = dirInfo.FullName;
                    }
              }
              catch (Exception ex) {
                FullPath = "";
              }
          ]]>
          </Code>
      </Task>
    

    <AbsolutePath Path="$(BuildSolutionDir)$(DeployDir)Website">
            <Output TaskParameter="FullPath" PropertyName="FullPath" />
        </AbsolutePath>
    <Message Text="$(FullPath)"/>
    

    tks.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多