I have a problem with using Phantom do delete and copy recursively. I have already solved the actual problem which was quite easy checking the below exception anyone could easily do so but can you tell me how to reproduce the problem from visual studio?
System.IO.DirectoryNotFoundException:
Could not find a part of the path
‘build/webui\Views/Web.config’. at
System.IO.__Error.WinIOError(Int32
errorCode, String maybeFullPath) at
System.IO.File.InternalCopy(String
sourceFileName, String destFileName,
Boolean overwrite) at
Phantom.Core.WrappedFileInfo.CopyToDirectory(String
path) in
d:\OpenSource\Build\Phantom2\Phantom\src\Phantom.Core\WrappedFileInfo.cs:line
75 at
build.$$Execute$closure$23$closure$25.Invoke(WrappedFileSystemInfo
file) at
Phantom.Core.Builtins.UtilityFunctions.ForEach[T](IEnumerable11 action) in
source, Action
d:\OpenSource\Build\Phantom2\Phantom\src\Phantom.Core\Builtins\UtilityFunctions.cs:line
34 at
build.$Execute$closure$23.Invoke()
at Phantom.Core.Target.Execute() in
d:\OpenSource\Build\Phantom2\Phantom\src\Phantom.Core\Target.cs:line
81 at
Phantom.Core.ScriptModel.ExecuteTargets(String[]
targetNames) in
d:\OpenSource\Build\Phantom2\Phantom\src\Phantom.Core\ScriptModel.cs:line
73 at
Phantom.Program.Execute(String[] args)
in
d:\OpenSource\Build\Phantom2\Phantom\src\Phantom\Program.cs:line
57
The problem is that phantom is started from .bat/.cmd file and the build file is sent as an argument and this fails somehow on my Windows 7 x64 machine but doing the exact same thing from within Visual Studio 2008 works perfectly so even if I copy the Views folder I can do so recursively. The original code (that fails from the command line):
public override void CopyToDirectory(string path) {
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
if (Flatten) {
var combinedPath = Path.Combine(path, Name);
File.Copy(FullName, combinedPath, true);
}
else {
var combinedPath = Path.Combine(path, PathWithoutBaseDirectory);
File.Copy(FullName, combinedPath, true);
}
}
Changing the above to:
public override void CopyToDirectory(string path) {
if (!Directory.Exists(path)) {
Directory.CreateDirectory(path);
}
if (Flatten) {
var combinedPath = Path.Combine(path, Name);
File.Copy(FullName, combinedPath, true);
}
else {
var combinedPath = Path.Combine(path, PathWithoutBaseDirectory);
var newPath = Path.GetDirectoryName(combinedPath);
if (!Directory.Exists(newPath)) {
Directory.CreateDirectory(newPath);
}
File.Copy(FullName, combinedPath, true);
}
}
makes that specific problem go away which is fine I mean figuring it out only took a couple of minutes but trying to reproduce the problem or create a failing test has taken quite a few hours now and I’d like to know why it can’t be done or learn how 🙂
Edit: The reason for this is extremely silly but here goes. The base directory in this case would be “Views” the PathWithourBaseDirectory would be equal to something like “Home/About.aspx” the darn thing would not work in cmd but it did work in Visual Studio. Next thing I know I can’t make it run in Visual Studio either so I applied my fix and all tests turn green. I still don’t know why…
Well – there are several problems:
Let’s say path is “C:\Foo\Bar.txt” (where Bar.txt is a text-file).
Now you are calling Directory.CreateDirectory(path).
You try to create the directory “C:\Foo\Bar.txt”. However, that “is” already a file.
Then, when creating the file, you combine this path with the file name – a result might be “C:\Foo\Bar.txt\Bar.txt”. This however, can not succeed.