How do you handle excluded files with aspnet_compiler?
Asked Answered
G

4

10

I'm trying to use aspnet_compiler to move a project that has already compiled from one location to another. I'm using Subversion for revision control.

The process basically gets all the code out of subversion, does a build, then calls aspnet_compiler.

My problem comes into being when I've got an excluded ascx file. This file is part of the latest code, but the normal build compiler ignores it, so no trouble. Aspnet_compiler blows up, however, because it cannot find the code behind for that particular control.

I'm not sure if

  • I'm doing this right;
  • there's a way to just get the correct file tree from Subversion
  • There's an easier way; or
  • this is expected, and I need to delete excluded files every time.

I'd appreciate any help.

Tom

Guaranty answered 7/3, 2011 at 17:47 Comment(2)
If your ASCX control is no longer required, why don't you delete it? With Subversion, you'll still have access to the file via the older revisions.Enarthrosis
We have deleted it from the solution, but when we use Subversion to get the project, it gets all the files, including the one not used.Guaranty
T
3

This is expected: Aspnet_compiler.exe compiles all files in the application and does not look at the project file. Thus, it does not have any notion of an excluded file.

Babak Naffas's suggestion of deleting the file is probably the easiest way of dealing with the file, rather than manually deleting it (or scripting its deletion) each time.

Trichosis answered 17/3, 2011 at 6:42 Comment(0)
L
11

Since .NET 4.5 or 4.5.1 (I am not sure which) there was a -x option added to aspnet_compiler.exe which allows you to exclude directories from compilation. You can find the option through command "aspnet_compiler /?".

-x            The virtual path of a directory that should be excluded from precompilation.
This switch can be used multiple times.

Example:

There is a folder named "ToBeExcluded" in my website. I can use the following command to pre-compile the website and exclude that folder,

aspnet_compiler -v /foo -p "C:\MyWebsite" -x ToBeExcluded "c:\temp\web"
Lockwood answered 2/11, 2015 at 18:14 Comment(1)
Does this -x ToBeExcluded "c:\temp\web" also apply to a file... for example -x ToBeExcluded "c:\temp\web\myfile.rdlc"Racecourse
T
3

This is expected: Aspnet_compiler.exe compiles all files in the application and does not look at the project file. Thus, it does not have any notion of an excluded file.

Babak Naffas's suggestion of deleting the file is probably the easiest way of dealing with the file, rather than manually deleting it (or scripting its deletion) each time.

Trichosis answered 17/3, 2011 at 6:42 Comment(0)
T
2

I was struggling for so long with this. But finally found an workaround

attrib +h folderToExclude & runAspComplierWithAllOptions & attrib -h folderToExclude

Hide folder -> compile -> show folder.

Textualist answered 4/4, 2017 at 10:32 Comment(0)
G
2

There is a very easy way to do it: set the hidden attribute to the folder to exclude, and aspnet_compiler will skip it.

A typical case for this error is the node_modules folder created by npm install

If you run npm install from a script, or from the command line, you can run the attrib command, after running nmp install to hide the folder:

attrib +H node_modules

If you run npm install from a msbuild project, you can add an exec task, like this:

<PropertyGroup>
    <HideFolder>attrib +H "$(PackageJsonFolder)\node_modules"</HideFolder>
</PropertyGroup>
<!-- next line is for debugging, remove it when finished -->
<Warning Text="Hide node_modules command: '$(HideFolder)'"/>
<Exec Command="$(HideFolder)">

The exitcode for attrib command is always zero, at least in my tests, so it makes no sense to check it to determine if the command run successfully.

In the previous msbuild example the folder to hide is "$(PackageJsonFolder)\node_modules" because the property PackageJsonFolder is the name of the folder where packages.json file is, and thus where node_modules will be created.

For other cases you can always specify your folder relative to the project's location, like this:

<HideFolder>attrib +H "$(MSBuildProjectDirectory)\folder\to\hide"</HideFolder>

and run the command using the same lime in the previous example.

Goosy answered 9/4, 2018 at 14:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.