自定义Gradle Visual Studio插件以生成vcxproj.user
我正在尝试自定义默认的Visual Studio Gradle插件任务,以便为解决方案中的每个可执行项目(我想跳过库)沿vcxproj文件生成vcxproj.user文件 其思想是查找GenerateProjectFileTask类型的所有任务,以某种方式仅过滤表示可执行二进制文件的任务(这部分我还不知道如何做)和finalizedBy子句,使它们运行我的任务,该任务也将生成.user文件 我需要这个,因为我的项目有一个自定义的自定义Gradle Visual Studio插件以生成vcxproj.user,gradle,Gradle,我正在尝试自定义默认的Visual Studio Gradle插件任务,以便为解决方案中的每个可执行项目(我想跳过库)沿vcxproj文件生成vcxproj.user文件 其思想是查找GenerateProjectFileTask类型的所有任务,以某种方式仅过滤表示可执行二进制文件的任务(这部分我还不知道如何做)和finalizedBy子句,使它们运行我的任务,该任务也将生成.user文件 我需要这个,因为我的项目有一个自定义的工作目录路径,每次添加新的源文件等时,我都必须重新生成项目。显然,当
工作目录
路径,每次添加新的源文件等时,我都必须重新生成项目。显然,当我这样做时(清理后),我必须为每个可执行文件重新设置这些路径。这很烦人
到目前为止我想做的是
subprojects {
// every proejct with plugin cpp also uses visual-studio plugin
plugins.withId('cpp') {
afterEvaluate {
tasks.withType(GenerateProjectFileTask) { task ->
def project = task.getVisualStudioProject()
if(project != null) {
println project.projectFile.location
}
else {
println "Project is null"
}
//println task.getOutputFile().getPath() <- this didnt work either
task.finalizedBy "someGeneratedTaskForEachProjectToCreateUserProperties"
}
}
}
}
子项目{
//每个带有插件cpp的项目也使用visual studio插件
plugins.withId('cpp')){
后评价{
tasks.withType(GenerateProjectFileTask){task->
def project=task.getVisualStudioProject()
如果(项目!=null){
println project.projectFile.location
}
否则{
println“项目为空”
}
//println task.getOutputFile().getPath()好的,由于没有答案,我将回答我自己的问题,因为我解决了这个问题,尽管我对它不是最满意,因为它不漂亮我想:
subprojects { subproj ->
plugins.withId('cpp') {
model {
components {
withType(NativeExecutableSpec) { c ->
subproj.tasks.whenTaskAdded {
if(it.name == "${c.name}VisualStudio") {
it.dependsOn task("${c.name}_${c.name}VisualStudioUserProperties", type:Task) {
def projectTask = tasks["${c.name}_${c.name}ExeVisualStudioProject"]
def path = projectTask.outputs.files.singleFile.parentFile.absolutePath
def outputPath = "${path}/${c.name}_${c.name}Exe.vcxproj.user"
inputs.file(file("data/vsDebuggerWorkingDirectory.xml"))
outputs.file(outputPath)
doLast {
new File(outputPath).write(("${inputs.files.singleFile.text}"))
}
mustRunAfter "${c.name}_${c.name}ExeVisualStudioProject"
}
}
}
}
}
}
}
}