cross_platform_csproj 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +15 -0
- data/lib/cross_platform_csproj.rb +97 -0
- metadata +51 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Mark Wong
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
= cross_platform_csproj
|
2
|
+
|
3
|
+
Tools for creating cross platform CSharp projects. Best for creating a common library that compiles to Windows, MonoDevelop and MonoTouch.
|
4
|
+
|
5
|
+
Offers functions which synchronize the file and folder structure to a CSharp project. Users maintain a cross platform CSharp library using the file system. Running these functions will update CSProject files to any changes as done on the file system. This was particularly built for creating cross platform libraries that would work with Windows, MonoAndroid and MonoTouch.
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
* files = FileList.new('Source/**/*.cs')
|
10
|
+
* CrossPlatformCSProj::updateProject('Source/MyProject.csproj', files)
|
11
|
+
|
12
|
+
== Copyright
|
13
|
+
|
14
|
+
Copyright (c) 2013 Tyler Hamilton and Mark Wong. See LICENSE.txt for
|
15
|
+
further details.
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
|
3
|
+
class CrossPlatformCSProj
|
4
|
+
|
5
|
+
def self.updateProject(projectFile, fileList)
|
6
|
+
rootPath = File.dirname(projectFile).gsub('/', '\\')
|
7
|
+
document = openDocument(projectFile)
|
8
|
+
parent = getParentNode(document)
|
9
|
+
|
10
|
+
if parent != nil
|
11
|
+
parent.children.remove
|
12
|
+
|
13
|
+
for file in fileList do
|
14
|
+
compileNode = Nokogiri::XML::Node.new 'Compile', document
|
15
|
+
|
16
|
+
parent.add_child(compileNode)
|
17
|
+
|
18
|
+
relativeFile = getRelativePath(file, rootPath)
|
19
|
+
|
20
|
+
compileNode.set_attribute('Include', relativeFile)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
saveDocument(document, projectFile)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.openDocument(projectFile)
|
30
|
+
fileHandle = File.open(projectFile)
|
31
|
+
document = Nokogiri::XML(fileHandle) do |config|
|
32
|
+
config.default_xml.noblanks
|
33
|
+
end
|
34
|
+
fileHandle.close
|
35
|
+
|
36
|
+
return document
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.saveDocument(document, projectFile)
|
40
|
+
documentContents = document.to_xml(:indent => 4)
|
41
|
+
|
42
|
+
fileHandle = File.open(projectFile)
|
43
|
+
documentContentsOld = fileHandle.read
|
44
|
+
fileHandle.close
|
45
|
+
|
46
|
+
# Only write to the file if there has been changes. This will allow updateProject to be called many times without Visual Studio from needing to reload the project
|
47
|
+
if documentContentsOld != documentContents
|
48
|
+
fileHandle = File.open(projectFile, 'w')
|
49
|
+
fileHandle.puts(documentContents)
|
50
|
+
fileHandle.close
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.getParentNode(document)
|
55
|
+
nodes = document.css('Project > ItemGroup')
|
56
|
+
parentNode = nil
|
57
|
+
|
58
|
+
for node in nodes do
|
59
|
+
if (node.css('Compile').length > 0)
|
60
|
+
if (parentNode != nil)
|
61
|
+
puts "ERROR: more than one ItemGroup element has Compile elements"
|
62
|
+
return nil
|
63
|
+
end
|
64
|
+
|
65
|
+
parentNode = node
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if parentNode == nil
|
70
|
+
projectNode = document.css('Project')
|
71
|
+
|
72
|
+
if projectNode.length == 0
|
73
|
+
puts 'ERROR: invalid CSharp project file'
|
74
|
+
return nil
|
75
|
+
end
|
76
|
+
|
77
|
+
parentNode = Nokogiri::XML::Node.new('ItemGroup', document)
|
78
|
+
|
79
|
+
projectNode.add_next_sibling(parentNode)
|
80
|
+
end
|
81
|
+
|
82
|
+
return parentNode
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.getRelativePath(path, pathRelative)
|
86
|
+
pathRelative = pathRelative.gsub('/', '\\')
|
87
|
+
path = path.gsub('/', '\\')
|
88
|
+
path = path.gsub(pathRelative, "")
|
89
|
+
|
90
|
+
if (path.length > 0 and path.start_with?('\\'))
|
91
|
+
return path[1..path.length - 1]
|
92
|
+
end
|
93
|
+
|
94
|
+
return path
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cross_platform_csproj
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tyler Hamilton, Mark Wong
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-31 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Offers functions which synchronize the file and folder structure to a
|
15
|
+
CSharp project. Users maintain a cross platform CSharp library using the file system. Running
|
16
|
+
these functions will update CSProject files to any changes as done on the file system. This
|
17
|
+
is particularly useful for creating cross platform libraries that would work with
|
18
|
+
Windows, MonoAndroid and MonoTouch.
|
19
|
+
email: xqdeveloper@gmail.com
|
20
|
+
executables: []
|
21
|
+
extensions: []
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- lib/cross_platform_csproj.rb
|
25
|
+
- README.rdoc
|
26
|
+
- LICENSE.txt
|
27
|
+
homepage: http://github.com/markslwong/CrossPlatformCSProj
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 1.8.24
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: Tools for creating cross platform CSharp projects.
|
51
|
+
test_files: []
|