Results 1 to 6 of 6

Thread: How to Add files generated by custom task to .csproj?

  1. #1
    Join Date
    Aug 2006
    Posts
    209

    How to Add files generated by custom task to .csproj?

    When I use the custom task in a .csproj file, it generates some new files. All I want to know is How to Add files generated by custom task to .csproj ?? Because I want the files the files that I created should get added to the project during the build, so that they appear in the solution explorer in Visual Studio. Does anyone know the idea of adding the files generated by my task to the project? Please help me as soon as possible..!!
    Blessings to you

  2. #2
    Join Date
    Apr 2008
    Posts
    2,139

    Re: How to Add files generated by custom task to .csproj?

    Here is the procedure (bit lengthy) to Add files generated by custom task to .csproj. It will be a little complex to use the DTE Automation in your task and then adding the generated files programmatically through the ProjectItems.AddFromFile Method. Also you will need to handle the multiple instance of Visual Studio in the ROT. But you can try this even it is lengthy but will surely work for you. If you want more information regarding the using of DTE Automation, you can go to the MSDN. Hope that this reply will help you.

  3. #3
    Join Date
    May 2008
    Posts
    3,316

    Re: How to Add files generated by custom task to .csproj?

    I think that the way I mentioned is more easy about adding the files generated by custom task to .csproj :
    First modify your .csproj file to pre-add the place holder for these files :
    <ItemGroup>
    <Compile Include="File1.xx" />
    <Compile Include="File2.xx" />
    </ItemGroup>
    After you execute the task, it will appear in Solution Explorer. I think that your task must be executed "Before the Build".

  4. #4
    Join Date
    May 2008
    Posts
    4,345

    Re: How to Add files generated by custom task to .csproj?

    I was having the similar doubt..But when I tried to do the add the files that were generated by the custom task to .csproj by using the programmatic approach through the ProjectItems.AddFromFile Method. Then after I was able to add the generated files to .csproj . Hope that same will help you too. If you are not able to add even after that sent the more details about the problem.

  5. #5
    Join Date
    May 2008
    Posts
    4,570

    Re: How to Add files generated by custom task to .csproj?

    The another method to add files generated by custom task to .csproj using the Microsoft.Build.Evaluation, mentioned below :

    var project = ProjectCollection.GlobalProjectCollection.LoadedProjects
    .Where(p => p.FullPath.ToLower() == ProjectFile.ToLower())
    .FirstOrDefault();
    project.AddItem(...)

    But there is drawback of this method. You will have to reload the project file whenever you have added new items to the project.

  6. #6
    Join Date
    Apr 2008
    Posts
    4,642

    Re: How to Add files generated by custom task to .csproj?

    According to me you should be having the .NET v4 which has the assembly for using the Microsoft.Build (in Microsoft.Build.dll). Otherwise you will not get the assembly if it is lower version of .NET. In such scenario you can use the method of adding the file in programmatic way, as mentioned by the 'chroma'. All you have to use is the DTE Automation in your task. This will be complex but will work for you.

Similar Threads

  1. Replies: 6
    Last Post: 25-08-2011, 11:34 PM
  2. Replies: 5
    Last Post: 30-04-2011, 09:53 PM
  3. Replies: 4
    Last Post: 27-01-2011, 01:22 PM
  4. Windows 7 recovery of XP generated .bkf files
    By Sawan123 in forum Operating Systems
    Replies: 4
    Last Post: 09-08-2010, 11:42 AM
  5. Cannot Open .csproj File
    By TimKell in forum Software Development
    Replies: 1
    Last Post: 16-04-2010, 02:00 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,904,928.36170 seconds with 17 queries