WiX权限 - 在预先存在的目录上设置权限

时间:2011-06-10 13:05:02

标签: permissions wix

我正在使用msbuild热包装器为我的网站安装程序生成组件列表,并试图找出如何在该树深处的文件夹上定义权限。

在我生成的wxs文件中,我有

<Directory Id="dirC092054A3A348CC48B696FD466A89A2F" Name="ExportFiles">
<Component Id="cmp699347B0054EDD7DD7B0935D39A66FAE" Guid="{5037..}">
  <File Id="..." KeyPath="yes" Source="SourceDir\Reports\ExportFiles\donotdelete.txt" />
</Component>
</Directory>

我意识到我可以在这里使用CreateFolder和Permission元素,但是这个文件在prebuild上重新生成,所以我每次都会丢失我的更改。是否有从我的主Product.wxs文件中设置ExportFiles文件夹的权限?

2 个答案:

答案 0 :(得分:1)

尽管Sunil的回答确实有效,但我找到了另一种我认为会分享的方式。

我正在使用概述here的技术让heat.exe获取我的网络应用程序的暂存输出,但需要进行一些修改:

<Target Name="BeforeBuild">
<MSBuild Projects="%(ProjectReference.FullPath)" Targets="Package" Properties="Configuration=$(Configuration);Platform=AnyCPU" Condition="'%(ProjectReference.WebProject)'=='True'" />
<Copy SourceFiles="%(ProjectReference.RootDir)%(ProjectReference.Directory)obj\$(Configuration)\TransformWebConfig\transformed\web.config" OverwriteReadOnlyFiles="true" DestinationFolder="%(ProjectReference.RootDir)%(ProjectReference.Directory)obj\$(Configuration)\Package\PackageTmp\" />
<PropertyGroup>
  <LinkerBaseInputPaths>%(ProjectReference.RootDir)%(ProjectReference.Directory)obj\$(Configuration)\Package\PackageTmp\</LinkerBaseInputPaths>
</PropertyGroup>
<HeatDirectory OutputFile="%(ProjectReference.Filename)-temp.xml" Directory="%(ProjectReference.RootDir)%(ProjectReference.Directory)obj\$(Configuration)\Package\PackageTmp\" DirectoryRefId="INSTALLLOCATION" ComponentGroupName="%(ProjectReference.Filename)_Project" SuppressCom="true" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" AutoGenerateGuids="false" GenerateGuidsNow="true" ToolPath="$(WixToolPath)" Condition="'%(ProjectReference.WebProject)'=='True'" />
<XslTransformation XmlInputPaths="%(ProjectReference.Filename)-temp.xml" XslInputPath="XslTransform.xslt" OutputPaths="%(ProjectReference.Filename).wxs" />

  • 首先,复制任务抓取正确转换的web.config,这似乎不是自己发生的(我在分阶段的配置文件中获得了令牌)。

  • 加热任务输出到临时XML文件,我通过XSLT转换为WXS文件,由WiX选取

继承XSLT:

<xsl:template match="@*|node()">
<xsl:copy>
  <xsl:apply-templates select="@*|node()" />
</xsl:copy>

<xsl:template match="w:Directory[@Name='ExportFiles']/w:Component">
<w:Component>
  <xsl:attribute name="Id">
    <xsl:value-of select="@Id"/>
  </xsl:attribute>
  <xsl:attribute name="Guid">
    <xsl:value-of select="@Guid"/>
  </xsl:attribute>
  <w:CreateFolder>
    <w:Permission User="Administrators" GenericAll="yes" />
    <w:Permission User="Network Service" GenericAll="yes" />
  </w:CreateFolder>
  <xsl:apply-templates select="*" />
</w:Component>

它只是重新创建文件,但ExportFiles文件夹除外,该文件夹添加了权限位: 之前:

<Directory Id="dirC092054A3A348CC48B696FD466A89A2F" Name="ExportFiles">
   <Component Id="cmp699347B0054EDD7DD7B0935D39A66FAE" Guid="{87D70A4F-A757-41C2-8AC9-E2904479FD45}">
     <File Id="filEC20935A3F97F24E20E1C2041AC766CA" KeyPath="yes" Source="SourceDir\Reports\ExportFiles\donotdelete.txt" />
    </Component>
   </Directory>

后:

<Directory Id="dirC092054A3A348CC48B696FD466A89A2F" Name="ExportFiles">
  <w:Component Id="cmp699347B0054EDD7DD7B0935D39A66FAE" Guid="{87D70A4F-A757-41C2-8AC9-E2904479FD45}"
    xmlns:w="http://schemas.microsoft.com/wix/2006/wi">
    <w:CreateFolder>
      <w:Permission User="Administrators" GenericAll="yes" />
      <w:Permission User="Network Service" GenericAll="yes" />
    </w:CreateFolder>
    <File Id="filEC20935A3F97F24E20E1C2041AC766CA" KeyPath="yes" Source="SourceDir\Reports\ExportFiles\donotdelete.txt" />
  </w:Component>
 </Directory>

这是一个非常好的做事方式,我已经使用相同的技术来做其他一些事情。希望其他人也能发现它有用。

答案 1 :(得分:-1)

创建自定义操作,然后设置文件夹的权限。使用此代码

string directory = session["PATH"] + "Temp";
if (Directory.Exists(directory))
{
    DirectoryInfo dInfo = new DirectoryInfo(directory);
    DirectorySecurity dSecurity = dInfo.GetAccessControl();
    dSecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl,
            InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None,
            AccessControlType.Allow));
    dInfo.SetAccessControl(dSecurity);
}

此代码将使文件夹与所有人共享。

相关问题