2011-06-10 161 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> 

其相當做的事情,我的一個很好的方式已經使用相同的技術來做其他一些事情。希望別人也能找到它有用。