c# - Avoid to set Copy To Output Directory with new csproj format -
i created vs2017 solution using "new" csproj
format, it's web .net 4.6.1 application written using nancyfx, serving pages thru owin , iis.
all views under views
folder if don't set copy output
options iis cannot find them (the same true custom config files).
the problem, think, output directory automatically set bin\net461\win7-x86
instead of bin
, working directory of web app set output dir, have set copy output
option.
how can use new csproj format retain ability edit view files without rebuilding app? tried set output folder bin
ignored. tried set the working directory value in debug tab no avail. set values in every configuration (debug/release) that's not issue.
this csproj file:
<project sdk="microsoft.net.sdk.web"> <propertygroup> <targetframework>net461</targetframework> <runtimeidentifier>win7-x86</runtimeidentifier> </propertygroup> <propertygroup condition="'$(configuration)|$(platform)'=='release|x86'" /> <itemgroup> <folder include="wwwroot\" /> </itemgroup> <itemgroup> <packagereference include="microsoft.applicationinsights.aspnetcore" version="2.0.0" /> <packagereference include="microsoft.aspnetcore" version="1.1.2" /> <packagereference include="microsoft.aspnetcore.owin" version="1.1.2" /> <packagereference include="mongodb.driver" version="2.4.4" /> <packagereference include="nancy" version="2.0.0-clinteastwood" /> <packagereference include="nancy.authentication.forms" version="2.0.0-clinteastwood" /> <packagereference include="nancy.authentication.stateless" version="2.0.0-clinteastwood" /> <packagereference include="nancy.bootstrappers.unity" version="2.0.0-clinteastwood" /> <packagereference include="nancy.serialization.jsonnet" version="2.0.0-clinteastwood" /> <packagereference include="nancy.validation.fluentvalidation" version="2.0.0-clinteastwood" /> <packagereference include="newtonsoft.json" version="10.0.2" /> </itemgroup> <itemgroup> <content include="views\*.sshtml"> <copytooutputdirectory>preservenewest</copytooutputdirectory> </content> </itemgroup> <itemgroup> <reference include="microsoft.csharp" /> <reference include="system.configuration" /> </itemgroup> </project>
after 2 days spent trying found root cause of problem: not vs/csproj problem rather nancyfx 2.0 configuration issue.
for interested here steps followed fix problem:
- implement
irootpathprovider
configured return value ofihostingenvironment.contentrootpath
takenstartup
class - register custom
irootpathprovider
inbootstrapper
overridingirootpathprovider rootpathprovider { get; }
- by default in nancyfx 2.0 view always cached, in debug mode (see ticket), in
bootstrapper
override configure method shown below.
method bootstrapper.configure
:
public override void configure(inancyenvironment environment) { base.configure(environment); #if debug // disable view caching in debug mode environment.views(true, true); #endif }
now views read vs project directory (and not bin folder) , not cached, no more rebuilds between every view change. in csproj
can put:
<none include="views\**\*.sshtml" />
Comments
Post a Comment