Transforming crossdomain.xml on publish in asp.net web application

大憨熊 提交于 2020-01-06 14:26:32

问题


I'm attempting to transform crossdomain.xml for different environments, just like regular web.config files. I've tried using SlowCheetah add-in for visual studio, but it doesn't play well with web applications. It kept publishing transform files along with the transformed file, which i didn't want. Moreover, it did that for web.config transformation as well.

My other thought was to rename the file and all transforms to crossdomain.$(Configuration).config in hopes that VS would pick it up and transform it and then rename it somewhere in the build process to crossdomain.xml. But VS wouldn't transform it at all. Here is what my transforms look like at the moment.

crossdomain.config

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain- policy.dtd">
<cross-domain-policy>
   <allow-access-from domain="*" secure="false" />
</cross-domain-policy>

crossdomain.stage.config

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
   <allow-access-from domain="*.foo.com" secure="true" xdt:Transform="Replace" />
</cross-domain-policy>

Does anybody have any suggestions?

UPDATE The more i spend time on this, the more i realize that deployments in .NET are a complete nightmare. Still trying to figure this out. Looks like VS publishing feature does some sort of half-assed deployment. It calls up MSBuild to gather files to deploy and then deploys it manually outside of MSBuild. So, there is no way to get the deployment path to do the transform. I'd have to stub it into MSBuild as a parameter.


回答1:


Hate to be answering my own question, but the following link helped get this straightened out:

https://stackoverflow.com/a/5381408/546709

<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)\transformed\%(DestinationRelativePath)</TransformOutputFile>
    <TransformScope>$([System.IO.Path]::GetFullPath($(_PackageTempDir)\%(DestinationRelativePath)))</TransformScope>
</WebConfigsToTransform>
   <WebConfigsToTransformOuputs Include="@(WebConfigsToTransform->'%     (TransformOutputFile)')" />
</ItemGroup>
</Target>


来源:https://stackoverflow.com/questions/9745632/transforming-crossdomain-xml-on-publish-in-asp-net-web-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!