如何在没有可编译代码的 C# 项目上使用 MSBuild

发布于 2024-08-11 08:33:07 字数 1582 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

太阳公公是暖光 2024-08-18 08:33:07

您可以覆盖 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.

嘿哥们儿 2024-08-18 08:33:07

在文件的顶部,您有 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.

挽心 2024-08-18 08:33:07

“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).

日记撕了你也走了 2024-08-18 08:33:07

对此的快速解决方法是向项目添加一个虚拟页面。之后构建就可以工作了。

A quick fix for this would be to add a dummy page to the project. The build would work after that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文