如何在没有可编译代码的 C# 项目上使用 MSBuild
我有一个 C# Web 应用程序项目,其中实际上没有 ASP.Net 或 C#。它只是一个带有一些 Javascript、CSS 和一些图像的 html 页面。
我想使用 MSBuild 将此应用程序的一个版本部署到具有缩小的 JS 和 CSS 的输出文件夹。
使用以下代码,我收到错误“CSC:致命错误 CS2008:未指定输入”。我猜测是因为没有实际的 C# 代码可供编译,但我不确定。
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<CssTidy>..\build_tools\csstidy.exe</CssTidy>
</PropertyGroup>
<PropertyGroup>
<DeploymentFolder>Test\</DeploymentFolder>
<SourceProject>..\..\Test\Test.csproj</SourceProject>
</PropertyGroup>
<Import Project="Common.Web.targets" />
<ItemGroup>
<CssFiles Include="..\..\Test\CSS\stylesheet.css" />
<ScriptFiles Include="..\..\Test\JavaScript\javascript.js"/>
</ItemGroup>
<Target Name="compress_css">
<Attrib Files="%(CssFiles.FullPath)" ReadOnly="false"/>
<Exec Command="$(CssTidy) %(CssFiles.FullPath) %(CssFiles.FullPath) --template=highest" />
</Target>
<Target Name="compress_js">
<Attrib Files="%(ScriptFiles.FullPath)" ReadOnly="false"/>
<JSCompress Files="%(ScriptFiles.FullPath)"></JSCompress>
</Target>
<Target Name="call_targets">
<CallTarget Targets="compress_css"/>
<CallTarget Targets="compress_js"/>
</Target>
</Project>
我怎样才能做到这一点?
I have a C# web app project which actually has no ASP.Net or C# in it. It's just a single html page with some Javascript, CSS, and a couple of images.
I want to use MSBuild to deploy a version of this app to an output folder with minified JS and CSS.
With the following code, I get an error "CSC: fatal error CS2008: No inputs specified." I'm guessing because the there is no actual C# code to compile but I'm not sure.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<PropertyGroup>
<CssTidy>..\build_tools\csstidy.exe</CssTidy>
</PropertyGroup>
<PropertyGroup>
<DeploymentFolder>Test\</DeploymentFolder>
<SourceProject>..\..\Test\Test.csproj</SourceProject>
</PropertyGroup>
<Import Project="Common.Web.targets" />
<ItemGroup>
<CssFiles Include="..\..\Test\CSS\stylesheet.css" />
<ScriptFiles Include="..\..\Test\JavaScript\javascript.js"/>
</ItemGroup>
<Target Name="compress_css">
<Attrib Files="%(CssFiles.FullPath)" ReadOnly="false"/>
<Exec Command="$(CssTidy) %(CssFiles.FullPath) %(CssFiles.FullPath) --template=highest" />
</Target>
<Target Name="compress_js">
<Attrib Files="%(ScriptFiles.FullPath)" ReadOnly="false"/>
<JSCompress Files="%(ScriptFiles.FullPath)"></JSCompress>
</Target>
<Target Name="call_targets">
<CallTarget Targets="compress_css"/>
<CallTarget Targets="compress_js"/>
</Target>
</Project>
How can I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以覆盖 CoreCompile 目标并且不执行任何操作:
。这将跳过其活动并继续。您可能必须覆盖其他目标以避免错误。You could override the CoreCompile target and do nothing there:
<Target name="CoreCompile" />
. This will skip its activities and move on. You may have to override additional targets to avoid errors.在文件的顶部,您有 DefaultTargets="Build"
将“Build”更改为“call_targets”,您应该可以开始了。
At the top of the file you have the DefaultTargets="Build"
Change "Build" to "call_targets" and you should be good to go.
“common.web.targets”里面有什么?我假设错误是从该文件中的目标(或其导入的另一个目标)生成的。
What is inside "common.web.targets"? I assume that the error is generated from a target in that file (or another that it imports).
对此的快速解决方法是向项目添加一个虚拟页面。之后构建就可以工作了。
A quick fix for this would be to add a dummy page to the project. The build would work after that.