2011-06-10 101 views
1

我使用msbuild heat wrapper为我的网站安装程序生成组件列表,并试图找出如何定义该树中深层文件夹的权限。WiX权限 - 在预先存在的目录上设置权限

在我的生成文件的WXS我有

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

而且我知道我可以在这里使用一个CreateFolder和权限的元素,但这个文件是再生的预生成所以我每次都失去我的变化。有没有在我的主Product.wxs文件中设置ExportFiles文件夹的权限?

+1

解决方案使用XCACLS作为自定义操作:http://support.microsoft.com/kb/318754。这样您就可以在路径上设置权限而不是使用ID。 – 2011-06-10 13:46:48

回答

0

创建一个自定义操作,然后在该文件夹上设置权限。使用此代码

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); 
} 

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

+0

这可行,但我最终使用了下面概述的解决方案 – 2011-06-14 09:00:47

1

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

我使用概述here获得heat.exe抢我的web应用程序的调试输出的技术,但一对夫妇的修改:

<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文件以通过维克斯

继承人的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> 

其相当做的事情,我的一个很好的方式已经使用相同的技术来做其他一些事情。希望别人也能找到它有用。