English 中文(简体)
1. 用烟雾改造档案
原标题:Transforming files with msdeploy

我能否利用“智商”的智商改造机制改造其他档案?

最佳回答

(another approach)

在为贵项目经营的MSbuild中,烟雾包装被 invoked。

<>TransformXml是一项包含在一.csproj或.vsproj建筑中的任务。

只是修改你的建设过程,在你需要的任何档案中援引这项任务。

例如,我们做的是书写习俗目标。

<Target Name="TransformFile">

    <TransformXml Source="$(DestinationPath)$(Sourcefile)" 
       Transform="$(DestinationPath)$(TransformFile)" 
       Destination="$(DestinationPath)$(DestFile)" />
    </Target>

接着修改了你执行这项“义务”的任务。

<CallTarget Targets="TransformFile" 
   Condition=" $(CustomTransforms) == true " />
问题回答

泰勒的回答对我不利,他没有提供进一步的细节。 因此,我打入了Microsoft.Web.Publishing.targets文档,以找到解决办法。 以下MSBuild Target可添加到项目档案中,以便把其他所有集束文档转换为根基应用目录。 收到:

<Target Name="TransformOtherConfigs" AfterTargets="CollectWebConfigsToTransform">
<ItemGroup>
    <WebConfigsToTransform Include="@(FilesForPackagingFromProject)"
                           Condition=" %(FilesForPackagingFromProject.Extension) == .config "
                           Exclude="*.$(Configuration).config;$(ProjectConfigFileName)">
    <TransformFile>%(RelativeDir)%(Filename).$(Configuration).config</TransformFile>
    <TransformOriginalFile>$(TransformWebConfigIntermediateLocation)original\%(DestinationRelativePath)</TransformOriginalFile>
    <TransformOutputFile>$(TransformWebConfigIntermediateLocation)	ransformed\%(DestinationRelativePath)</TransformOutputFile>
    <TransformScope>$([System.IO.Path]::GetFullPath($(_PackageTempDir)\%(DestinationRelativePath)))</TransformScope>
  </WebConfigsToTransform>
  <WebConfigsToTransformOuputs Include="@(WebConfigsToTransform-> %(TransformOutputFile) )" />
</ItemGroup>
</Target>

www.un.org/Depts/DGACM/index_spanish.htm 简短回答: 是的。 但它是“扩散”。

Long answer: When we deploy sites to destinations we had the usual web.test.config, and web.prod.config. This worked fine until we introduced log4net.test.config and log4net.prod.config. MSBuild will not automatically go through and replace all of these. It will only do the web.config ones.

如果你想要特尼特大就去看最后的法典。 它显示了以替换换成一个会议的职能。 但是,如果我描述整个进程,它将更有意义。

进程:

  1. Msbuild makes a zip file package of the site.
  2. We wrote a custom .net app that will take that zip file and do the config replacements on each one of the files. Resave the zip file.
  3. Execute the msdeploy command to deploy the packaged file.

管理系统建设不会自动取代所有额外的会议。 有趣的是MSBuild将消除任何“外派”会议。 因此,请登录4net。 紧接着会conf。 因此,你必须做的第一个事情就是说,要保留这些额外的档案。

您必须修改其档案,以包括一个新情况:

<AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>

开放您的书刊,供您的主文编辑使用。 在每个部署的组合中,你也希望这样做(请、提议、辩论等),并补充说,这样做。 这是我们“释放”会议的一个例子。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  ...
  <PropertyGroup Condition="  $(Configuration)|$(Platform)  ==  Release|AnyCPU  ">
    <DebugType>pdbonly</DebugType>
    <DefineDebug>false</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <Optimize>true</Optimize>
    <OutputPath>bin</OutputPath>
    <DocumentationFile>Documentation.xml</DocumentationFile>
    <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022,42353,42354,42355</NoWarn>
    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    <DeployIisAppPath>IISAppPath</DeployIisAppPath>
    <AutoParameterizationWebConfigConnectionStrings>False</AutoParameterizationWebConfigConnectionStrings>
  </PropertyGroup>
  ...
</Project>

因此,现在布木工将建设项目,保留这些额外档案,而不是替代文件。 现在,你们必须手工操作。

我们撰写了一份蚊帐,将观察这些新的齐普文档。 我撰写了一些法典,将贯穿整个齐普一揽子计划,并找到与{configname}.{env}.config相吻合的任何组合。 它将取而代之,将其退回。 为了进行实际替换,我们使用了同样的DLL,即MSDeploy。 我也使用日志。 Zip去做zi。

添加以下文字:

Microsoft.Build.dll
Microsoft.Build.Engine.dll
Microsoft.Web.Publishing.Tasks (possibly, not sure if you need this or not)

进口:

Imports System.IO
Imports System.Text.RegularExpressions
Imports Microsoft.Build.BuildEngine
Imports Microsoft.Build 

这里是穿过zi子的法典。

specificpackage = "mypackagedsite.zip"
configenvironment = "DEV"  stupid i had to pass this in, but it s the environment in web.dev.config

Directory.CreateDirectory(tempdir)

Dim fi As New FileInfo(specificpackage)

 copy zip file to temp dir   
Dim tempzip As String = tempdir & fi.Name

File.Copy(specificpackage, tempzip)

  extract configs to merge from file into temp dir
 regex for the web.config 
 regex for the web.env.config
 (?<site>w+).(?<env>w+).config$

Dim strMainConfigRegex As String = "/(?<configtype>w+).config$"
Dim strsubconfigregex As String = "(?<site>w+).(?<env>w+).config$"
Dim strsubconfigregex2 As String = "(?<site>w+).(?<env>w+).config2$"

Dim MainConfigRegex As New Regex(strMainConfigRegex, RegexOptions.Compiled Or RegexOptions.IgnoreCase)
Dim SubConfigRegex As New Regex(strsubconfigregex, RegexOptions.Compiled Or RegexOptions.IgnoreCase)
Dim SubConfigRegex2 As New Regex(strsubconfigregex2, RegexOptions.Compiled Or RegexOptions.IgnoreCase)

Dim filetoadd As New Dictionary(Of String, String)
Dim filestoremove As New List(Of ZipEntry)
Using zip As ZipFile = ZipFile.Read(tempzip)
    For Each entry As ZipEntry In From a In zip.Entries Where a.IsDirectory = False
        For Each myMatch As Match In MainConfigRegex.Matches(entry.FileName)
            If myMatch.Success Then
                 found main config. 
                 re-loop through, find any that are in the same dir as this, and also match the config name
                Dim currentdir As String = Path.GetDirectoryName(entry.FileName)
                Dim conifgmatchname As String = myMatch.Groups.Item("configtype").Value

                For Each subentry In From b In zip.Entries Where b.IsDirectory = False _
                                     And UCase(Path.GetDirectoryName(b.FileName)) = UCase(currentdir) _
                                     And (UCase(Path.GetFileName(b.FileName)) = UCase(conifgmatchname & "." & configenvironment & ".config") Or
                                          UCase(Path.GetFileName(b.FileName)) = UCase(conifgmatchname & "." & configenvironment & ".config2"))

                    entry.Extract(tempdir)
                    subentry.Extract(tempdir)

                     Go ahead and do the transormation on these configs
                    Dim newtransform As New doTransform
                    newtransform.tempdir = tempdir
                    newtransform.filename = entry.FileName
                    newtransform.subfilename = subentry.FileName
                    Dim t1 As New Threading.Tasks.Task(AddressOf newtransform.doTransform)
                    t1.Start()
                    t1.Wait()
                    GC.Collect()
                     sleep here because the build engine takes a while. 
                    Threading.Thread.Sleep(2000)
                    GC.Collect()

                    File.Delete(tempdir & entry.FileName)
                    File.Move(tempdir & Path.GetDirectoryName(entry.FileName) & "/transformed.config", tempdir & entry.FileName)
                     put them back into the zip file
                    filetoadd.Add(tempdir & entry.FileName, Path.GetDirectoryName(entry.FileName))
                    filestoremove.Add(entry)
                Next
            End If
        Next
    Next

     loop through, remove all the "extra configs"
    For Each entry As ZipEntry In From a In zip.Entries Where a.IsDirectory = False

        Dim removed As Boolean = False

        For Each myMatch As Match In SubConfigRegex.Matches(entry.FileName)
            If myMatch.Success Then
                filestoremove.Add(entry)
                removed = True
            End If
        Next
        If removed = False Then
            For Each myMatch As Match In SubConfigRegex2.Matches(entry.FileName)
                If myMatch.Success Then
                    filestoremove.Add(entry)
                End If
            Next
        End If
    Next

     delete them
    For Each File In filestoremove
        zip.RemoveEntry(File)
    Next

    For Each f In filetoadd
        zip.AddFile(f.Key, f.Value)
    Next
    zip.Save()
End Using

最后,最重要的是,我们实际上在更换网络。

Public Class doTransform
    Property tempdir As String
    Property filename As String
    Property subfilename As String
    Public Function doTransform()
         do the config swap using msbuild
        Dim be As New Engine
        Dim BuildProject As New BuildEngine.Project(be)
        BuildProject.AddNewUsingTaskFromAssemblyFile("TransformXml", "$(MSBuildExtensionsPath)MicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.Tasks.dll")
        BuildProject.Targets.AddNewTarget("null")
        BuildProject.AddNewPropertyGroup(True)
        DirectCast(BuildProject.PropertyGroups(0), Microsoft.Build.BuildEngine.BuildPropertyGroup).AddNewProperty("GenerateResourceNeverLockTypeAssemblies", "true")

        Dim bt As BuildTask
        bt = BuildProject.Targets("null").AddNewTask("TransformXml")

        bt.SetParameterValue("Source", tempdir & filename)
        bt.SetParameterValue("Transform", tempdir & subfilename)
        bt.SetParameterValue("Destination", tempdir & Path.GetDirectoryName(filename) & "/transformed.config")
         bt.Execute()
        BuildProject.Build()
        be.Shutdown()

    End Function

End Class

和我一样,它非常困难,但可以做。

只是为了修改网络以外的其他档案,添加到这个名字。 在与烟雾(webdeploy)共同出版的申请书中,你可以在项目根基的参数中确定cop/属性。

<parameters>
  <parameter name="MyAppSetting" defaultvalue="_defaultValue_">
    <parameterentry match="/configuration/appSettings/add[@key= MyAppSetting ]/@value" scope=".exe.config$" kind="XmlFile">
    </parameterentry>
  </parameter>
</parameters>

http://www.un.org/Depts/DGACM/index_french.htm 我曾广泛尝试过这种试验,但只要我理解,它就只能取代过去那种与后来所提供的价值相匹配的东西。

也可用于<条码>实物的其他数值,其行为不同于xpath,见

note: 这适用于您在使用参数时,而不是在使用网络时。 Debug/Releasefile





相关问题
How can I get TFS2010 to run MSDEPLOY for me through MSBUILD?

There is an excellent PDC talk available here from Vishal Joshi which describes the new MSDEPLOY features in Visual Studio 2010 - as well as how to deploy an application within TFS. (There s also a ...

MSBuild target package not found

I want to package my VS2010 web application project ready for deployment with msdeploy. On development machine I can do this using: MSBuild.exe "C:path oWebApp.csproj" /target:package But on my ...

_CopyWebApplication with web.config transformations

I am trying to have my web application automatically Publish when a Release build is performed. I m doing this using the _CopyWebApplication target. I added the following to my .csproj file: <!--...

Opinions on MSDeploy

You know, the next "big" and "enterprisey" thing from Microsoft. Is it just me, or is it really hardly for humans? Main highlights are (IMO): Absolutely cryptic syntax (-skip:objectName=filePath,...