2009-09-26 33 views
6

Tôi tiếp tục nhìn thấy các tham chiếu đến Mage, nhưng tôi không hiểu cụ thể những gì nó làm và tại sao nó hữu ích/phổ biến. Nếu ai đó có thể cho một tóm tắt nhanh chóng của nó, nó sẽ được nhiều đánh giá cao!Mage là gì và theo cách nào là hữu ích?

Cảm ơn ~

Trả lời

6

Mage.exe là một thế hệ Manifest và Chỉnh sửa Nội dòng lệnh Công cụ cho các ứng dụng .NET Framework. Ngoài ra còn có một phiên bản giao diện người dùng MageUI.exe

Cách sử dụng thông thường là tạo thủ công ClickOnce deployment manifests của bạn.

0

Nó được sử dụng cho các ứng dụng ký ClickOnce

9

Mitch mì đã đưa ra một câu trả lời tuyệt vời, và nếu bạn chỉ cần bắt đầu với Mage, đọc các liên kết cuối cùng ông cho!

tôi muốn chia sẻ một số mã thực để cung cấp cho những người khác giúp đỡ với các dự án ClickOnce của họ. Tôi thấy rằng việc sử dụng MSBUILD from the command-line to "create" the deployment là điều hoàn hảo cho quá trình tạo tự động. Tôi không bao giờ thi hành thuật sĩ Xuất bản từ Visual Studio. Mặc dù, tôi chỉ định rõ tất cả thông tin trên tab Publish trong VS, do đó tôi không phải thực hiện nó từ dòng lệnh. Ví dụ: "Tệp ứng dụng" là thứ mà tôi không biết cách thực hiện trên dòng lệnh.

THEN sau khi ứng dụng được thành công triển khai đến máy chủ ... Tôi sử dụng "Mage" như một phần của di cư của tôi về việc triển khai ClickOnce từ một máy chủ khác (ví dụ Testing-> Staging-> Sản xuất)

Ví dụ (một kịch bản PowerShell mà xây dựng giải pháp của bạn chạy từ một công việc CruiseControl):

&"$Env:windir\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" "C:\Projects\MyCoolApp.sln" /t:clean /t:publish /p:Configuration=Release /p:ApplicationRevision=$Env:CCNETLABEL /p:PublishDir="\\TestServer\MyCoolAppFolder/" /p:PublishUrl="\\TestServer\MyCoolAppFolder/" 

Rồi sau đó, khi bạn muốn di chuyển ứng dụng ClickOnce của bạn từ "Tuyên chiến" thành "QAServer" hoặc "Staging" hoặc "Sản xuất "... bạn sẽ cần phải viết một kịch bản phức tạp để làm điều đó. Dưới đây là những gì tôi đã đưa ra:

######################################################################################### 
# PowerShell Script to Migrate a ClickOnce Deployment from one server to another. 
# This is my first attempt at PowerShell... pardon the bad or incorrect code. :-) 
# To run a PowerShell script from CruiseControl.Net: 
# http://www.cruisecontrolnet.org/projects/ccnet/wiki/PowerShell_Task 
# NOTE: When doing the initial build, ensure that the ProviderURL and ProviderDir are set. 
######################################################################################### 

$SourceDir = "\\TestServer\MyCoolAppFolder" 
$DestDir = "\\StagingServer\MyCoolAppFolder" 
$DeploymentManifestName = "MyCoolApp.application" 
$DeploymentDestUrl = "file://StagingServer/MyCoolAppFolder" 

# If your application is one that connects to a database, then likely you want it to point 
# to a different database depending what environment it's been deployed to. 
# I use a SQL Server connection for this example. 
$ConnStringName = "MyCoolAppConnectionString" 
$ConnStringValue = "data source=StagingServerInstance;Initial Catalog=MyCoolAppDB;persist security info=True;user id=Gregg;password=Gregg" 

# Unfortunately, you *must* specify the publisher when doing Mage, even though you specified it 
# when you did the original publish, otherwise Mage will change the Publisher value to the 
# name of your Application. A bug in Mage I suspect. 
$Publisher = "Gregg Cleland" 

# Risk: This next line assumes that the pfx certificate file is readily available. 
# Just be certain it's the same key you used when you published originally. 
$AuthenticationKeyPath = "C:\Projects\MyCoolApp\MyCoolApp_TemporaryKey.pfx" 

# Note: This references the .NET 3.5 version of mage... the .NET 4.0 version of mage.exe can be found at: 
# C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\mage.exe 
$MAGE = "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\mage.exe" 

######################################################################################### 
# Start off at the source location. 
Set-Location $SourceDir 

######################################################################################### 
# Get the application manifest directory name and application manifest file name. 
[xml]$doc = Get-Content $DeploymentManifestName 
$ns = New-Object Xml.XmlNamespaceManager $doc.NameTable 
$ns.AddNamespace("asmv1", "urn:schemas-microsoft-com:asm.v1") 
$ns.AddNamespace("asmv2", "urn:schemas-microsoft-com:asm.v2") 
$xpath = "/asmv1:assembly/asmv2:dependency/asmv2:dependentAssembly" 
$appManifestPath = $doc.SelectSingleNode($xpath, $ns).codebase # Example: = "Application Files\MyCoolApp_1_0_0_5\MyApp.exe.manifest" 
$position = $appManifestPath.LastIndexOf('\'); 
$appManifestDir = $appManifestPath.SubString(0, $position); # Example: "Application Files\MyCoolApp_1_0_0_5" 
$appManifestFile = $appManifestPath.SubString($position + 1); # Example: "MyCoolApp.exe.manifest" 

######################################################################################### 
# Copy the deployment files and the latest application files to destination. 
# Note: Do not forget to ensure the CruiseControl Service Logon has permissions to write to destination! 
# Todo: If robocopy fails, throw "robocopy failed!" Most likely it is an Error 5, Access Denied 
# b/c the CruiseControl Service logon account doesn't have permission to copy to create/write to destination. 
$CurrentDir = "$DestDir\$appManifestDir" 
robocopy "$SourceDir" "$DestDir" /XO 
robocopy "$SourceDir\$appManifestDir" $CurrentDir /MIR /XO 

######################################################################################### 
# Now that we have copied the latest build, let us navigate down into the destination's 
# application manifest directory and do some work. 
Set-Location $CurrentDir 

######################################################################################### 
# Remove the .deploy extension from all files. (Mage will throw an exception if you don't do this) 
Get-ChildItem -Include *.deploy -Recurse | Rename-Item -NewName { [System.IO.Path]::ChangeExtension($_.Name, "") } 

######################################################################################### 
# Modify the XML in the app.config file per your needs (e.g. change the connectionStrings) 
[xml]$doc = Get-Content $AppConfigFileName 

$node = $doc.SelectSingleNode("configuration/connectionStrings/add[@name='$ConnStringName']") 
$node.connectionString = $ConnStringValue 

$xmldocPath = $PWD.ProviderPath # hack to avoid getting the silly namespace prefixed to the path for UNC paths 
$doc.Save("$xmldocPath\$AppConfigFileName") # For some reason, seems to require the fully qualified path 

######################################################################################### 
# Finally... We get to the part where we use MAGE! 
# Use MAGE to update the application manifest hash and sign it. 
&"$MAGE" -Update $appManifestFile -FromDirectory "$CurrentDir" -CertFile $AuthenticationKeyPath 

######################################################################################### 
# Re-Add the ".deploy" extension to all files EXCEPT those that end in "application" or 
# "manifest". Do this AFTER signing. 
Get-ChildItem -Recurse | Where-Object { !$_.PSIsContainer -and !$_.Name.EndsWith(".application") -and !$_.Name.EndsWith(".manifest") } | Rename-Item -NewName { $_.Name + ".deploy" } 

######################################################################################### 
# Finally, go back up to the Deployment folder and update the deployment manifest 
Set-Location "..\..\" 
&"$MAGE" -Update $DeploymentManifestName -ProviderUrl "$DeploymentDestUrl/$DeploymentManifestName" -AppManifest "$appManifestPath" -Publisher $Publisher -CertFile $AuthenticationKeyPath 
+0

rằng tập lệnh PowerShell thật tuyệt vời! Cám ơn rất nhiều vì cái đó. –

Các vấn đề liên quan