I believe I've found a bug with including binary files in projects created from a .xpt template file.
Steps to reproduce:
1) Create an image file called ProjectTemplateBinaryFileBug.bmp (actually any binary file will do)
2) Create a project template file called ProjectTemplateBinaryFileBug.xpt with the following content
<?xml version="1.0"?>
<Template originator="Simon Bridewell" created="07/12/2016">
<TemplateConfiguration>
<Name>Binary file bug reproduction</Name>
<Category>C#</Category>
<Icon>C#.Project.Library</Icon>
<Description>Reproduces a bug with including binary files in .xpt project templates.</Description>
<SupportedTargetFrameworks>v2.0,v3.0,v3.5,v4.0,v4.5</SupportedTargetFrameworks>
</TemplateConfiguration>
<Project name="${ProjectName}" language="C#">
<Files>
<File name="ProjectTemplateBinaryFileBug.bmp" src="ProjectTemplateBinaryFileBug.bmp" binary="true" />
</Files>
</Project>
</Template>
3) Copy both files to the data\templates\project\CSharp folder within the SharpDevelop installation folder
4) Within SharpDevelop, either create a new solution or add a project to an existing solution, in either case selecting the C# project template called "Binary file bug reproduction" and calling the project "Bug".
Expected result:
New project created with default content plus the binary file created in step 1.
Actual result:
SharpDevelop Version : 5.1.0.5134-RC-d5052dc5
.NET Version : 4.6.01586
OS Version : Microsoft Windows NT 6.3.9600.0
Current culture : English (United Kingdom) (en-GB)
Running under WOW6432, processor architecture: x86-64
Working Set Memory : 108552kb
GC Heap Memory : 12624kb
Exception writing C:\Users\Simon\Documents\SharpDevelop Projects\Bug\Bug\ProjectTemplateBinaryFileBug.bmp
Exception thrown:
System.IO.FileNotFoundException: Could not find file 'ProjectTemplateBinaryFileBug.bmp'.
File name: 'ProjectTemplateBinaryFileBug.bmp'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
at ICSharpCode.SharpDevelop.Templates.ProjectDescriptor.CreateProject(ProjectTemplateResult templateResults, String defaultLanguage, ISolutionFolder target)
The project is created, but the reference to the binary file has a warning icon indicating that the file doesn't exist.
After doing a debug build and some stepping through, it turns out that SharpDevelop is trying to find this file in its bin folder rather than its actual location within the data\templates folder (I wasn't able to work out why, sorry). Only files with the binary="true" attribute are affected.
I also tried installing the 5.2 beta from the build server but got more or less the same exception:
SharpDevelop Version : 5.2.0.5230-Beta-ba372efb
.NET Version : 4.6.01586
OS Version : Microsoft Windows NT 6.3.9600.0
Current culture : English (United Kingdom) (en-GB)
Running under WOW6432, processor architecture: x86-64
Working Set Memory : 108508kb
GC Heap Memory : 14781kb
Exception writing C:\Users\Simon\Documents\SharpDevelop Projects\Bug\Bug\ProjectTemplateBinaryFileBug.bmp
Exception thrown:
System.IO.FileNotFoundException: Could not find file 'ProjectTemplateBinaryFileBug.bmp'.
File name: 'ProjectTemplateBinaryFileBug.bmp'
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
at ICSharpCode.SharpDevelop.Templates.ProjectDescriptor.CreateProject(ProjectTemplateResult templateResults, String defaultLanguage, ISolutionFolder target)
Workaround:
Change the src attribute of the File element in the .xpt file from "ProjectTemplateBinaryFileBug.bmp" to "..\data\templates\project\csharp\ProjectTemplateBinaryFileBug.bmp" (or put the binary file in SharpDevelop's bin folder - probably not a good idea!)
Thanks
Simon
↧
Binary files in .xpt project templates
↧