Visual Studio Templates and environment variables - visual-studio

I have created a project template for Visual Studio 2010, and I have an environment variable I setted up in every machine I use. The template references some resources which are located in the directory pointed in that environment variable.
A sample reference in the template is:
<ItemGroup>
<Compile Include="$(MyVariable)OneDir\MyFile.txt">
The key point is that when I create a proyect with this template, and in the .csproj I get:
<ItemGroup>
<Compile Include="..\..\..\..\Users\MyUser\AppData\......."/>
In the same .csproj I have replace it in the .csproj file whit:
<ItemGroup>
<Compile Include="$(MyVariable)OneDir\MyFile.txt">
So, is there any way to make the csproj writes "$(MyVariable" in the "Include" parameter?.
I have tried with the scape caracter %24 which correspond to the "$" character like it is saying in msdn [1]: http://msdn.microsoft.com/en-us/library/bb383819.aspx but i get this .csproj:
<ItemGroup>
<Compile Include="%24..\..\..\..\Users\MyUser\AppData\......."/>

Try workaround used in this post. It is about creating property from env variable and using it inside ItemGroup.

Related

How to include an <ItemGroup> across multiple .csproj files

Within Visual Studio (2019 in this case) solution, is there a way to specify an <ItemGroup> in a location that multiple .csproj files can use it within the solution?
As an example, this ItemGroup is used in multiple .csproj files within Test.sln. Instead of having to add this ItemGroup to each .csproj file, I'd like to somehow place it in a common file and reference it from the .csproj file. Is that possible?
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdk)" />
</ItemGroup>
You can use a Directory.Build.props file in the directory hierarchy (e.g. next to the .sln file) containing only these common things:
<Project>
<ItemGroup>
...
</ItemGroup>
</Project>

.net core wwwroot data folder - Do Not Copy being ignored

So I have a simple .net core application that I am deploying to Azure from VS2019. I have some json files in the wwwroot\data folder and I have set them to content=none and copy="Do Not Copy".
However when I publish the still publish every time.
I have also edited the .csproj file and ensure this is there
<ItemGroup>
<None Include="wwwroot\data\file.json" CopyToPublishDirectory="Never"/>
</ItemGroup>
and yet it still publishes.
Any ideas
You can try following code:
<ItemGroup>
<Content Update="wwwroot\data\file.json">
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>

How do I add files to VS Solution Explorer with a wildcard in the project file?

In my project file I include all of the .cpp and .h files in a directory by using a wildcard as shown in the code snippet below. Everything compiles just fine.
The annoying issue I run into is I have to add files to the Solution Explorer manually via the Add Existing Item dialog. If I don't use a wildcard and spell out every file, I don't have the same problem. Not something I want to do with a boatload of source files though.
Is there a way to get these wildcard includes into the Solution Explorer?
<ItemGroup>
<ClCompile Include="$(SrcDir)\*.cpp" >
<Link>%(FileName)</Link>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(SrcDir)\*.h">
<Link>%(RecursiveDir)\%(FileName)</Link>
</ClInclude>
</ItemGroup>

Conditional compilation new csproj and visual studio solution explorer

I have the following in my csproj file
<ItemGroup>
<Compile Remove="WebControls/**/*" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<Compile Remove="Lucene/**/*" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
</ItemGroup>
I'm not even sure if this is the right approach, I'm trying to avoid having to go through those files and add a conditional compilation symbol such as "#if NET462".
The problem is that those files disappear from the solution explorer when I add that to csproj, is there a way to switch the target platform to net462 in the solution explorer so that they show again?

Visual Studio, csproj: How can I specify a linked file in DependentUpon?

Suppose I have a default.aspx.cs in my project, but I want to make it dependent upon the default.aspx file that's linked. E.g.:
<Content Include="..\somedir\default.aspx">
<Link>Default.aspx</Link>
</Content>
This doesn't work:
<Compile Include="default.aspx.cs">
<DependentUpon>Default.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
This also doesn't work:
<Compile Include="default.aspx.cs">
<DependentUpon>..\somedir\default.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
For both, I get this error:
The parent file, 'Default.aspx', for file 'default.aspx.cs' cannot be found in the project file.
Is it possible to have a file be dependent upon a linked file?
I tried the same thing and it seems is not supported. Check this: https://bitbucket.org/jfromaniello/nestin/issue/4/error-when-nesting-linked-files "DependentUpon does not work with linked files."

Resources