NAnt MVC 发布网站
问题:我想用 NAnt 优雅地发布一个 MVC 网站。
简单不?错了...以下是我查看过的一些 stackoverflow 资源。他们每个人都有一个问题......
Stackoverflow 1: 使用 NAnt 发布 WebApplication
这一结果是 web.config 没有被转换,并且垃圾箱中出现了其他文件,这些文件不应该像所有东西的entity.dll.config 一样!
Stackoverflow 2: 从命令行复制 VS2008“发布网站”
这个将执行与之前的解决方案相同的操作,但它更糟糕...它将复制我的项目中的所有内容并将其转储到发布文件夹中...不是开玩笑!
Stackoverflow 3: MSBuild 脚本和 VS2010 发布应用 Web.config 转换
可接受的解决方案构建在 Stackoverflow 1 之上,但是纯 MsBuild xml,而不是 NAnt xml。它还只修复了 Webconfig,因此仍然保留显示的随机文件。 pattersonc 还提供了另一种解决方案(未接受),该解决方案非常非常接近正确,但 web.config 中的连接字符串处于虚假的不稳定状态,给您留下了另一个错误的 web.config
不用说它是已经 3-4 天了,10 多个不同的 StackOverFlow 答案,但没有灵丹妙药……没有简单的解决方案吗?我是否必须犯下一些大罪并创建一些极其混乱的 NAnt 脚本才能获得 VS2010 如此出色地提供的正确发布结果?
Problem: I want to elegantly publish an MVC website with NAnt.
Simple no? Wrong... Here are some of the stackoverflow resources I've looked at. Each one of them has an issue...
Stackoverflow 1:
Publish WebApplication using NAnt
The result of this one was that the web.config was not being transformed and additional files were showing up in the bin that weren't suppose to like the entity.dll.config of all things!
Stackoverflow 2:
Replicate VS2008 "Publish Web Site" from command line
This one will do the same as the previous solution except it's even worse... it will copy EVERYTHING from my project and dump it into the publish folder... no joke!
Stackoverflow 3:
MSBuild Script and VS2010 publish apply Web.config Transform
The accepted solution builds on top of Stackoverflow 1, but is pure MsBuild xml and not NAnt xml. It also only fixes the Webconfig and so still leaves those random files that show up. There is also another solution (not accepted) that pattersonc gives, which is very, very close to correct but the connection strings in the web.config are in a bogus limbo state, leaving you with yet another bad web.config
Needless to say it's been 3-4 days, 10+ different StackOverFlow answers and no silver bullet... Is there no easy solution? Must I commit some cardinal sin and create some horribly messed up NAnt script to achieve the correct publish results that VS2010 delivers so nicely?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我偶然发现这个博客后就明白了,
http://blogs.msdn.com/ b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx
在步骤 4 中,他显示了一个我以前从未见过的命令行参数,
/t:TransformWebConfig
不幸的是,仅此并不能解决问题。它确实执行转换,但转换位于 obj/Release/TransformWebConfig/transformed/Web.config (obj/Release 或 obj/Debug 或 obj/YourTranformName)中。
所以为了最终得到一个像样的解决方案,这就是我必须做的。
请注意,OutDir 与 WebProjectOutputDir 不同。这就是为什么:
项目“解决方案”。
网络“项目”的最低限度
(即不是整个解决方案)。
使用 OutDir 的解决方案中的其他项目带来了很多我们不想要的额外包袱,因此我们只是将 OutDir 发送到临时文件夹并删除,如您在上面的步骤中看到的那样。顺便说一句,OutDir 是绝对必需的。如果删除它,构建将无法工作。似乎 WebProjectOutputDir 是在 OutDir 之外工作的。
整个设置只有一个小缺陷。 bin 库中缺少许多 pdb 文件。唯一复制的 pdb 是来自 Web 项目的 pdb。
如果有人找到 MSBuild 的一步解决方案,请发布:P
尽管这是一个很好的解决方案,但它仍然只有 99.9999% 的完美度,而且很像上面列出的解决方案,我确信会有一些细微差别或遗漏的步骤。
Okay I figured it out after chancing on this blog,
http://blogs.msdn.com/b/webdevtools/archive/2009/05/04/web-deployment-web-config-transformation.aspx
In step 4 he shows a command line arg I haven't seen before,
/t:TransformWebConfig
Unfortunately, this alone does not solve the problem. It does perform the transform but the transform is found in obj/Release/TransformWebConfig/transformed/Web.config (obj/Release or obj/Debug or obj/YourTranformName).
So to finally get a decent solution this is what I had to do.
Notice that the OutDir is not the same as the WebProjectOutputDir. This is the reason why:
project "solution".
bare minimum for the web "project"
(i.e. not the entire solution).
A lot of extra baggage was coming over from other projects in the solution using OutDir that we didn't want so we just sent OutDir to a temp folder and deleted as you can see in the steps above. OutDir is absolutely required by the way. The build will not work if you remove it. Seems that WebProjectOutputDir works off of OutDir.
There is only one minor flaw with this entire setup. A lot of pdb files are missing from the bin library. The only pdb copied over was the one from the Web project.
If anyone ever finds a one step solution with MSBuild to this please post it : P
Although this is a good solution it is still only 99.9999% perfect and much like the ones listed above I'm sure there's going to be some little nuance or step missed.
查看您的解决方案后,我偶然发现了另一个解决方案 https://stackoverflow.com/a/2953376/662853
我修改了您的答案是使用 _WPPCopyWebApplication 目标:
测试后,我不再需要删除配置并复制转换后的文件。
After checking out your solution I stumbled across another solution https://stackoverflow.com/a/2953376/662853
I revised your answer to use the _WPPCopyWebApplication target instead:
After testing I no longer needed to delete the configs and copy the transformed files.