How do I use MSBuild on a C# project with no compilable code

2.4k Views Asked by At

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?

4

There are 4 best solutions below

0
On

What is inside "common.web.targets"? I assume that the error is generated from a target in that file (or another that it imports).

3
On

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.

0
On

At the top of the file you have the DefaultTargets="Build"

Change "Build" to "call_targets" and you should be good to go.

0
On

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