I have successfully included all my project files by putting these lines in my .csproj file:

```
<ItemGroup>
  <Content Include="**\*.*" Exclude="**\*.cs"></Content>
</ItemGroup>

<ItemGroup>
  <Compile Include="**\*.cs" Exclude="**\*.as?x.*"></Compile>

  <Compile Include="**\*.aspx.cs">
    <SubType>ASPXCodeBehind</SubType>
  </Compile>
  <Compile Include="**\*.ascx.cs">
    <SubType>ASPXCodeBehind</SubType>
  </Compile>
  <Compile Include="**\*.aspx.designer.cs"></Compile>
  <Compile Include="**\*.ascx.designer.cs"></Compile>
</ItemGroup>

```

and then I successfully copy all my files into another directory using these lines:

```
<Target Name="AfterRebuild">
    <Copy SourceFiles="@(Content)" DestinationFolder="\wwwroot\%(Content.RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="AfterRebuild">
  <Copy SourceFiles="@(Compile)" DestinationFolder="\wwwroot\%(Compile.RecursiveDir)" SkipUnchangedFiles="true" />
</Target>

```

The first problem I'm having is that every time I add another file to the project Visual Studio decides to regenerate every .designer.cs file include as well as add the new file include. It looks like this after adding the file:

```
<ItemGroup>
  <Compile Include="a_bunch_of_these.designer.cs" />
  <Compile Include="a_bunch_of_these.designer.cs" />
  <Compile Include="a_bunch_of_these.designer.cs" />
  ...

  <Compile Include="Business\WebForm1.aspx.designer.cs">
    <DependentUpon>WebForm1.aspx</DependentUpon>
  </Compile>

  <Compile Include="**\*.cs" Exclude="**\*.as?x.*"></Compile>

  <Compile Include="**\*.aspx.cs">
    <SubType>ASPXCodeBehind</SubType>
  </Compile>
  <Compile Include="**\*.ascx.cs">
    <SubType>ASPXCodeBehind</SubType>
  </Compile>
  <Compile Include="**\*.aspx.designer.cs"></Compile>
  <Compile Include="**\*.ascx.designer.cs"></Compile>
</ItemGroup>

```

to the project. The second problem I'm having is less important, but still slightly annoying. I don't have a dependantupon attribute in the Item elements under the ItemGroup elements, so in the solution explorer the files are not coupled together:
[See WebForm1 vs WebForm2](http://i.stack.imgur.com/M53Ck.png)

I have two questions:

1. How do I stop Visual Studio from adding those new lines? Since it is being included twice in the project it shows up twice in the solution explorer which is very annoying.
2. How do I associate a DependentUpon element with each file when using a wildcard to choose the files? Is there a way to mine the name out of the chosen file to relatively associate an aspx file automatically? Something like:

---

```
<ItemGroup>
<Compile Include="**\*.aspx.cs">
  <SubType>ASPXCodeBehind</SubType>
  <DependentUpon>%(Filename)%(Extension)</DependentUpon>
</Compile>
</ItemGroup>

```

**EDIT:** Just so you guys can have a big picture of what I'm trying to do: My project is to automate the deployment of a website onto a server. I have decided to use Team City to do the CI. It clones the repo it's connected to, then builds the project. This code makes it so after the build is completed, the project will automatically be copied to the correct folder with the correct structure. 

I had also tried ftpUpload from msbuild community tasks, but the project is large and ftp takes a prohibitive amount of time.

The other thing I had looked at was WebDeploy, but seeing as I could find no documentation for Visual Studio 2015 projects with Web Deploy I just decided to try something else.